Login With Password Remembered
login with password remembered
With password remembered, the password must be encrypted in some way and stored in the cookie, actually there’s 3 cookies in header when user browser request for certification.
$.cookie('cn')
- username
$.cookie('ct')
- time stamp last login
$.cookie('ctoken')
- encrypted password or some other info required to be certificated by server
Then we know ctoken
is important, there’s problem- how to ensure the password is not cracked by hackers, below is a way to do some calculation like or with two strings.
Think about this: if we just simply encrypt the password with MD5, sha1… and store in browser, is that safe? Maybe, but the most keys are cracked with md5, or sha1…, so we should encrypt it with some more complicate way:
1 2 3 4 5 6 7 8 9 10 11 |
|
what’s xorString
, it creates a token for server validation. The xorString
gets two params - phash
which is the password encrypted in MD5, another is cthash
which is the username + timestamp + MD5(password)
encrypted in MD5. We can see the xorString
is handling the two strings in a special way. What will it?
1 2 3 4 5 6 7 8 |
|
It’s easy, just a or operation with each MD5 result, it’s an MD5 result again, but not the result of password. And although others know the token is some or result. It’s nearly impossible for them to crack it.
Of course, we can calculate the right token easily in the server side. Here’s a version of C#:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
We can store the ‘password’ safely in the browser.