Java mailbox password retrieval example code

The realization of the function of retrieving the password through e-mail. 1. A system has been developed recently. There is a need to retrieve the password through the e-mail after forgetting the password. The current system will force the mailbox to be entered when registering. One purpose is to retrieve the password by mail binding. I won't talk about the function of sending e-mail through Java, focusing on retrieving the password.

2. Refer to other people's ideas: send e-mail → request the URL in the e-mail → verify the URL → {verify the password successfully, and jump to the failure page if unsuccessful}

The key point is how to generate the URL and how to parse the URL It should be noted that a URL can only change the password once. When multiple emails are sent from the same account, there is only the URL mailbox of the last email

3. Encryption can prevent forgery attacks. A URL can only be verified once, and the user is bound. Generate URL: random key can be generated with UUID.

Digital signature = MD5 (user name + '' '+ expiration time +' '+ expiration time +' + key)

Database fields (user name (primary key), key, expiration time)

URL parameter (user name, digital signature), generation of key: generate a key for each user when they retrieve the password,

Generate expiration time, generate digital signature, generate URL and send mail Addu (user name, expiration time)

The databases used are as follows:

The password code for retrieving the mailbox is as follows:

Supplement 1: the millisecond precision of timestamp type objects will be lost when they are saved to data. For example, at 10:30:10.234 on May 20, 2014, when saved in the MySQL database, it becomes 10:30:10.0 on May 20, 2013. The time becomes different, and the SID matches will not be equal. So I did the operation of ignoring accuracy.

Supplement 2: solve the Chinese random code of title under Linux

Supplement 3: why not insert Sid directly into the users table. It is OK to directly compare Sid during verification.

Source code download address: http://pan.baidu.com/s/1cl8hKq

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>