JAVA Simple Implementation MD5 Registration login Encryption __java

Source: Internet
Author: User

Development environment: Jdk1.7,eclipse
Framework: Springmvc,mybatis
Tools: Maven
Following code replication enables MD5 encryption create a Mave project, plus the web. Don't know how to search it. Registers the user's JSP page code as follows.

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" Utf-8 "%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  

You need to build a userdto class yourself, and I use the Userdto property to pass the value.
also to introduce jquery MD5, search, I do not know how to upload this file to the above for you to download.
Http://pan.baidu.com/s/1bp9t8Vd to the network disk JSP landing page code,

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" Utf-8 "%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  
 then write the background code   
Package Com.test.controller;

Import Javax.annotation.Resource;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;

Import Org.springframework.web.servlet.ModelAndView;
Import Com.test.dao.UserDao;
Import Com.test.model.UserDto;    
    /** * * * @author halfway decent * */@Controller public class Userlogin {@Resource Userdao Userdao; * * Add User */@RequestMapping ("/insertuser") public Modelandview Insertuser (userdto userdto) {//Enter
        Line encryption, the page is passed not plaintext, is a hash value, and then encrypt the hash String s=userdto.getuser_psw ();
        String Smi=convertmd5 (s);
        USERDTO.SETUSER_PSW (SMI);
        Userdao.insertuser (userdto);
    return new Modelandview ("newfile.jsp");
        /* * Verify username/@RequestMapping ("/authuser") public Modelandview Authuser (userdto userdto) {
        int i=0;
        The hash password passed to the user login is encrypted first with String S=USERDTO.GETUSER_PSW ();
        String Smi=convertmd5 (s); AddUSERDTO.SETUSER_PSW (SMI) is compared with the password stored in the database.
        try {i=userdao.login (userdto);
        catch (Exception e) {//TODO auto-generated catch block E.printstacktrace ();
        } if (i==1) {System.out.println ("User logon succeeded");
        }else{System.out.println ("User Login failed");
    Return to New Modelandview ("newfile.jsp"); /** * Encryption decryption algorithm performs once encryption, two decryption/public static string ConvertMD5 (String inStr) {Char  
        [] A = Instr.tochararray ();  
        for (int i = 0; i < a.length i++) {A[i] = (char) (a[i] ^ ' t ');  
        string s = new String (a);  
    return s; }

}

This makes a simple MD5 encryption. Other default code is very simple, not all write out, read logic will do.
Attach the password saved in the database is this. The

is also a point of insufficient advice.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.