jQuery implements several methods of login encryption and cookie storage encryption/decryption

All operations in this article are carried out on the jsp page, completely separated from the background

part 1: encryption method

  This encryption method is basically summed up by many people on the Internet, so I will just throw some ideas here;

1. Base64 encryption

  Introduce the base64.js file into the page, and the calling method is:

   

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>base64加密</title>
<script type="text/javascript" src="base64.js"></script>
<script type="text/javascript">
var b = new Base64();
var str = b.encode("admin:admin");
alert("base64 encode:" + str);
     //解密
str = b.decode(str);
alert("base64 decode:" + str);
</script>
</head>

<body>
</body>
</html>

 

2, md5 encryption

  The md5.js file is referenced in the page, and the calling method is

  

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>md5加密</title>
<script type="text/ecmascript" src="md5.js"></script>
<script type="text/javascript">
var hash = hex_md5("123dafd");
alert(hash)
</script>
</head>

<body>
</body>
</html>

 

3. sha1 encryption

  It is said to be the most secure encryption

  sha1.js is introduced into the page, and the calling method is

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title> sha1 compaction </ title>
<script type="text/ecmascript" src="sha1.js"></script>
<script type="text/javascript">
var sha = hex_sha1('mima123465')
    alert(sha)   
</script>  
</head>

<body>
</body>
</html>

part 2: Encryption and Decryption

md5.js can only implement the encryption function, but if you take out the password from the cookie and want to decrypt it, it will be embarrassing, so here I recommend two methods for password encryption and decryption

 1.Base64.js

Don't talk nonsense, just look at the code (including how to save the username and password in the cookie on the jsp page)

 

<script>
     // step 1: when the mouse clicks the checkbox, create a persistent cookie 
    var userName= null ;
    var passWord = null ;
          // Limited to: Judging when the mouse clicks to log in: 
         $("#accLogBut" ).click(function(){
              /* Gray the login button */
         
             // If it is selected, create a cookie 
            if ($('input[type=checkbox]').is(':checked' )){
                passWord = $('#passWord' ).val();
                 // Create a cookie and save the username and password in it. The password is encrypted with base64 and decrypted 
                $.cookie('userName',$('#userName').val (), { expires: 7 });
                $.cookie('passWord',$.base64.encode(passWord),{ expires: 7});
            } else {
                 // If the checkbox is not checked, delete the cookie 
                
                $.cookie( 'userName', "" );
                $.cookie('passWord', ""); 
            }        
         });        
 // Every time the page is loaded, the value in the cookie is taken out and stored in the corresponding text box 
$(function(){
         
         var userName=$.cookie('userName');
        var passWord=$.cookie('passWord');
        
        $("#userName").val(userName);
        $("#passWord").val($.base64.decode(passWord));
         if(userName!=null&&userName!=""&&passWord!=null&&passWord!=""){
                
            $("#rememberPassword").attr("checked",true);
        }        
    
});
</script>
<!-- Remember password end when logging in -->

 

The above two methods are mainly used: $.base64.encode(str) encrypted string

 

$.base64.decode(str) decrypt the string

2. This is a relatively lightweight encryption and decryption process in the jquery plugin library

name is DES

1. Base64 encryption

  Introduce the base64.js file into the page, and the calling method is:

   

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>base64加密</title>
<script type="text/javascript" src="base64.js"></script>
<script type="text/javascript">
var b = new Base64();
var str = b.encode("admin:admin");
alert("base64 encode:" + str);
     //解密
str = b.decode(str);
alert("base64 decode:" + str);
</script>
</head>

<body>
</body>
</html>

 

2, md5 encryption

  The md5.js file is referenced in the page, and the calling method is

  

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>md5加密</title>
<script type="text/ecmascript" src="md5.js"></script>
<script type="text/javascript">
var hash = hex_md5("123dafd");
alert(hash)
</script>
</head>

<body>
</body>
</html>

 

3. sha1 encryption

  It is said to be the most secure encryption

  sha1.js is introduced into the page, and the calling method is

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title> sha1 compaction </ title>
<script type="text/ecmascript" src="sha1.js"></script>
<script type="text/javascript">
var sha = hex_sha1('mima123465')
    alert(sha)   
</script>  
</head>

<body>
</body>
</html>

part 2: Encryption and Decryption

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324489141&siteId=291194637