❮ Previous Next ❯

How to change password using JSP

Hii friends, in this context, we will see a nice concept which is the basic requirement in any login form or signup form in project development, that is how to change password code in JSP.

Here we have a form having 3 attributes like oldpassword, newpassword, confirmpassword. OldPassword is already saved in the database and when a user enters the OldPasswrod, the program checks it with the database and see if it matches or not. In the new password, it matches the password entered in the first field with the password entered in the second field and if both of them matches, it saves the password in the data as the new password.


Step-1: In Oracle environment, we will create a table named as let cpassword like;
create table cpassword
(
id varchar2(100) primary key,
oldpassword varchar2(100)
);

Step-2: Now we will go to eclipse environment to develop our Required Files:
Required Files:

  1. Password.jsp
  2. Process.jsp



Password.jsp
<html>
<body>
<script language="javascript">
function fncSubmit()
{

if(document.ChangePasswordForm.OldPassword.value == "")
{
alert('Input old password');
document.ChangePasswordForm.OldPassword.focus();
return false;
}

if(document.ChangePasswordForm.newpassword.value == "")
{
alert('Input Password');
document.ChangePasswordForm.newpassword.focus();
return false;
}

if(document.ChangePasswordForm.conpassword.value == "")
{
alert('Input Confirm Password');
document.ChangePasswordForm.conpassword.focus();
return false;
}

if(document.ChangePasswordForm.newpassword.value != document.ChangePasswordForm.conpassword.value)
{
alert('Confirm Password Not Match');
document.ChangePasswordForm.conpassword.focus();
return false;
}

document.ChangePasswordForm.submit();
}
</script>

<form name="ChangePasswordForm" method="post" action="process.jsp" OnSubmit="return fncSubmit();">

<table border="1" align="center" bgcolor="#2B60DE">

<tr>
<td>OLD PASSWORD</td>
<TD><input name="oldPassword" type="password" ></td>
</tr>
<tr>
<td>NewPassword</td>
<td><input name="newpassword" type="password" >
</td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input name="conpassword" type="password">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Save"></td>
</tr>

</table>
</form>
</body>
</html>

Process.jsp
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<html>
<body>
<%
String OldPassword = request.getParameter("oldPassword");
String Newpass = request.getParameter("newpassword");
String conpass = request.getParameter("conpassword");

Connection con = null;
Statement st = null;
String pass = "";
int id = 0;

try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:xe";
con = DriverManager.getConnection(url, "system", "oracle");
st = con.createStatement();
ResultSet rs = st.executeQuery("select * from cpassword where oldpassword= '"+ OldPassword + "'");

if (rs.next()) {
pass = rs.getString("oldpassword");
}

if(Newpass.equals(conpass))
{
if (pass.equals(OldPassword)) {
st = con.createStatement();
int i = st.executeUpdate("update cpassword set oldpassword='"+ Newpass + "'");

out.println("Password changed successfully");
st.close();
con.close();
} else {
out.println("Old Password doesn't match");
}
/*}else{
out.println("new password and confirm new password is not matching");
}*/
}
} catch (Exception e) {
out.println(e);
}
%>
</body>
</html>

Output
jsp change password

jsp change password
❮ Previous Next ❯


Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved