%@ page language="java" import="javax.naming.InitialContext,javax.sql.DataSource,java.sql.*,java.util.*,java.security.*,java.math.*" errorPage="error.jsp" %> <% int flag = 0; String uid="",pass="",old=""; String oldpass=""; uid = request.getParameter("txtUid"); pass = request.getParameter("txtPassword"); old = request.getParameter("oldpasswd"); Connection con = null; ResultSet rs= null; String url; url = (String) application.getInitParameter("DBResName"); try { InitialContext cxt = new InitialContext(); DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/"+url); if (ds == null) { throw new Exception("Data source not found!"); } con = ds.getConnection(); } catch(Exception e) { } Statement s = null; try { if(uid == null || uid.trim().length() == 0) { uid = ""; } else { s = con.createStatement(); rs = s.executeQuery("select * from user where userid = '" + uid + "'"); if(!rs.next()) { flag=1; } else { oldpass = rs.getString("password"); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(pass.getBytes()); BigInteger hash = new BigInteger(1,md.digest()); pass = hash.toString(16); md.update(old.getBytes()); BigInteger hash1 = new BigInteger(1,md.digest()); old = hash1.toString(16); } catch(NoSuchAlgorithmException e) { } if(oldpass.equals(old)) { s.executeUpdate("update user set password = '" + pass + "' where userid = '" + uid + "'"); response.sendRedirect("uconfirmpass.jsp"); } else { flag=2; } try { rs.close(); rs = null; s.close(); s = null; con.close(); con = null; } catch(Exception e) { } } } } catch(Exception e) { try { rs.close(); rs = null; s.close(); s = null; con.close(); con = null; } catch(Exception e1) { } } %>
| <%@ include file = "header.jsp" %> | ||
| <%@ include file = "footer.jsp" %> | ||