Due to the need of a business, I made a password modification sub-business.
When the user forgets the password, I need to send him a 6-bit random password, via instant Messenger, SMS, etc. And at the same time modify the original password in the database for this 6-bit random password. Ask the user to change the password again.
At the same time the password in the database must be stored as ciphertext, so you need to use to MD5 encryption. The generated 6-bit random password needs to be kept secret and cannot be processed in the foreground, only on the backend. So I chose to put it in the control layer.
//Pass in any text that needs to be encrypted Public Staticstring GetMd5 (String string) {Try{messagedigest MD= Messagedigest.getinstance ("MD5"); Md.update (String.getbytes ()); byteHash[] =md.digest (); StringBuffer SB=NewStringBuffer (); inti = 0; for(intoffset = 0; Offset < hash.length; offset++) {i=Hash[offset]; if(I < 0) {i+ = 256; } if(I < 16) {sb.append ("0"); } sb.append (Integer.tohexstring (i)); } returnsb.tostring (); } Catch(nosuchalgorithmexception e) {Throw NewRuntimeException (e); } }
The 32-bit encryption is used here, and the difference between 16-bit and 32-bit is that 16 bits are 32 bits in the middle of 16 bits.
String Password_ = string.valueof ((int) (Math.random () * 1000000)); if(Empservice.updateemppassword (Emp_id_, Baseutils.getmd5 (Password_), operator) = = 0) { Throw NewRuntimeException ("Random password generation failed!") "); } String Xele= "<SendMessage><AM_Name>" + Emp_code_ + "</am_name><phonenum></phonenum><userid ></UserId><MessageTxt> your document management system new password is: "+ password_ +" </MessageTxt><SystemName> Document management System < /systemname><type> Instant Messenger </type><access></access><email></email><isback ></isback><isencrypt></isencrypt><ispriority></ispriority><ohter1></ Ohter1><ohter2></ohter2></sendmessage><br/> ";
Then invoke the instant-pass reserved interface
null, operator);
Mainly look at the Java backend how to do MD5 encryption!!
Welcome everyone to read, a lot of comments on the shortcomings!!
For the engineer's road to building blocks!!
Java back-end authoring MD5 encryption