using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Web; namespace sci_project { public static class PasswordHelper { /// <summary> /// MD5 加密字符串 /// </summary>
在数据表中存的密码不应该是123456,而应该是123456加密之后的字符串,而且还要求这个加密算法是不可逆的,即由加密后的字符串不能反推回来原来的密码,如果能反推回来那这个加密是没有意义的.著名的加密算法,比如 MD5,SHA1.下面就来介绍如何用shiro进行MD5加密并验证 1.在注册的时候将前端传过来的密码入数据库之前进行加密 public void encryptPassword(User user) { String salt = new SecureRandomNumberGene
public class Test3 { /** * 生成含有随机盐的密码 */ public static String generate(String password) { Random r = new Random(); StringBuilder sb = new StringBuilder(16); sb.append(r.nextInt(99999999)).append(r.nextInt(99999999)); int len = sb.length(); if (len <