Educoder Java生成驗證碼
阿新 • • 發佈:2022-06-01
01
複製貼上沒難度, 過不去就是敲錯了...
02
PrintWriter writer = resp.getWriter(); String verifycode = req.getParameter("verifycode"); String username = req.getParameter("username"); String password = req.getParameter("password"); HttpSession session =req.getSession(); String realCode = (String) session.getAttribute("sessionYzm"); if(!verifycode.equals(realCode)){ writer.write("驗證碼錯誤"); }else{ // writer.write("驗證碼正確"); if(username.equals("admin") && password.equals("admin123")){ writer.write("登入成功"); }else{ writer.write("登入失敗"); } }
03
PrintWriter writer = resp.getWriter(); HttpSession session = req.getSession(); String trueCaptcha = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY); String inputCaptcha = req.getParameter("captcha"); if(trueCaptcha.toLowerCase().equals(inputCaptcha.toLowerCase())) { writer.write("驗證碼輸入正確"); } else { writer.write("驗證碼輸入錯誤"); }
還有個檔案同 01, 複製貼上沒難度
N/A
本來想發評論區的, 發現還要實名... 算了