日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

(五)密码加密

發布時間:2025/7/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (五)密码加密 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.louis.utils;import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException;public class MD5Utils {/*** 使用md5加密*/public static String md5(String plainText) {byte[] secretBytes = null;try {//普通的字符串轉化成數組secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());} catch (NoSuchAlgorithmException e) {throw new RuntimeException("找不到md5實例");}String md5code = new BigInteger(1, secretBytes).toString(16);for (int i = 0; i < 32 - md5code.length(); i++) {md5code = "0" + md5code;}return md5code;} /* //和數據庫的加密一樣,同一個字符串通過md5加密,結果是一樣的public static void main(String[] args) {System.out.println(md5("123"));}*/ } package com.louis.web.servlet;import java.io.IOException; import java.util.Date;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.ConvertUtils;import com.louis.domain.User; import com.louis.myconvertor.MyConverter; import com.louis.service.UserService; import com.louis.service.impl.UserServiceImpl; import com.louis.utils.MD5Utils; import com.louis.utils.UUIDUtils;/*** 和用戶相關的servlet*/public class UserServlet extends BaseServlet {public String add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {System.out.println("userServlet的add方法執行了");return null;}//調轉到注冊頁面public String registUI(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {return "/jsp/register.jsp";}//完成注冊public String regist(HttpServletRequest request,HttpServletResponse response) throws Exception {//1封裝數據User user = new User();//注冊自定義轉化器ConvertUtils.register(new MyConverter(), Date.class);BeanUtils.populate(user, request.getParameterMap());//1.1設置用戶id user.setUid(UUIDUtils.getId());//1.2設置激活碼 user.setCode(UUIDUtils.getCode());//1.3加密密碼 user.setPassword(MD5Utils.md5(user.getPassword()));//2調用service完成注冊UserService service = new UserServiceImpl();service.regist(user);//頁面請求轉發request.setAttribute("msg", "用戶已注冊,請去郵箱激活");return "/jsp/msg.jsp";}}

?

轉載于:https://www.cnblogs.com/Michael2397/p/7637055.html

總結

以上是生活随笔為你收集整理的(五)密码加密的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。