JSP MD5 program!

xiaoxiao2021-03-06  31

// There is no need to write a cryptographic method, and there is an coming package in Sun.

// Write an encrypted method ENCODEPASSWORD

Import java.security. *;

Public String EncodePassword (String Password) {Try {MessageDigest SHA = MessageDigest.getInstance ("SHA-1"); // Defines the MessageDigest object

Sha.Update (Password.getBytes ()); return new base64encoder (). ENCODE ();} catch (java.security.nosuchalgorithmexception e) {E.PrintStackTrace (); // Print error message; Return NULL;}}

-------------------------------------------------- ----------------------------------

The encrypted string is saved in your database field

The login check is followed by the following: String user = request.getParameter ("user"); string password = request.getParameter ("password"); // Get your password

String encpass = encodePassword (password); // MD5 encryption for password

Then perform a similar SQL statement preP = conn.preparestatement ("SELECT ID, NAME AERS WHERE NAME =? And password =?"); Prep.setstring (1, user); prep.setstring (2, encpass); ResultSet RS = preP.executeQuery ();

If the result set returns true, it is successful, then the login is successful. If false is not successful.

转载请注明原文地址:https://www.9cbs.com/read-64221.html

New Post(0)