Decrypt an encrypted password in JSP

How to decrypt an encrypted password and store in database ?

Her is my code that i have done for encryption

> <%@page
> import="java.sql.*,java.util.*"%>
> <%@page import=" java.security.*"%>
> <%@page import="javax.crypto.*"%>
> <%@page import="
> java.security.MessageDigest"%>
> 
> 
> 
> <% String
> fname=request.getParameter("fname");
> String
> lname=request.getParameter("lname");
> String
> email=request.getParameter("email");
> String
> pass=request.getParameter("password");
> String
> cpass=request.getParameter("confirm_password");
> String
> gender=request.getParameter("gender");
> String
> username=request.getParameter("uname");
> String
> phone=request.getParameter("phone");
> 
> 
> String algorithm="";
> 
> byte[] unencodedPassword =
> pass.getBytes(); MessageDigest md =
> null; try { md =
> MessageDigest.getInstance("MD5"); }
> catch (Exception e) {} md.reset();
> md.update(unencodedPassword); byte[]
> encodedPassword = md.digest();
> StringBuffer buf = new StringBuffer();
> for (int i = 0; i <
> encodedPassword.length; i++) { if
> (((int) encodedPassword[i] & 0xff) <
> 0x10) { buf.append("0"); }
> buf.append(Long.toString((int)
> encodedPassword[i] & 0xff, 16)); }
> String passw=buf.toString();
> 
>            
>       try{
>           System.out.println("Username::"
> +username);
>             Class.forName("com.mysql.jdbc.Driver");
>             Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo",
> "root", "root");
>             Statement st=con.createStatement();
>            int i=st.executeUpdate("insert into
> users(username,password,lastname,email,phone,gender,firstname,confirm_password)
> values('"+username+"','"+passw+"','"+lname+"','"+email+"','"+phone+"','"+gender+"','"+fname+"','"+cpass+"')");
>         out.println("Data is successfully inserted!");
>         }
>         catch(Exception e){
>         System.out.print(e);
>         e.printStackTrace();
>         }
>         
>         %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
> Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html> <head> <meta
> http-equiv="Content-Type"
> content="text/html;
> charset=ISO-8859-1">
> <title>Registration</title> </head>
> <body> </body
> 
> 
> </html>
View Answers

December 12, 2012 at 5:03 PM

The given allow the user to enter username, password along with other fields in order to submit the details into database. The password is first encrypted and then stored into database. If you want to get this password in decrypted form then you can use the decrypt function, created in the jsp.

1)form.jsp:

<html>
<body>
<form name="userform" method="post" action="encrypt.jsp">
<table>
<tr><td>User Name</td><td><input type="text" name="name"></td></tr>
<tr><td>Password</td><td><input type="password" name="pass"></td></tr>
<tr><td>Address</td><td><input type="text" name="address"></td></tr>
<tr><td>Contact No</td><td><input type="text" name="phone"></td></tr>
<tr><td><input type="submit" value="Search"></td></tr>
</table>
</form>
</body>
</html>

2)encrypt.jsp:

<%@page import="java.sql.*"%>
<%@page import=" java.security.*"%>
<%@page import="javax.crypto.*"%>
<%!
private static String algorithm = "DESede";
        private static Key key = null;
        private static Cipher cipher = null;
 private static byte[] encrypt(String input)throws Exception {
            cipher.init(Cipher.ENCRYPT_MODE, key);
            byte[] inputBytes = input.getBytes();
            return cipher.doFinal(inputBytes);
        }
%>
<%!
        private static String decrypt(byte[] encryptionBytes)throws Exception {
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] recoveredBytes =  cipher.doFinal(encryptionBytes);
            String recovered =  new String(recoveredBytes);
            return recovered;
          }
          %>
<%
String name=request.getParameter("name");
String password=request.getParameter("pass");
String address=request.getParameter("address");
String phone=request.getParameter("phone");
int ph=Integer.parseInt(phone);
StringBuffer buffer=new StringBuffer();
 key = KeyGenerator.getInstance(algorithm).generateKey();
            cipher = Cipher.getInstance(algorithm);
            String input = password;
            System.out.println("Entered: " + input);
            byte[] encryptionBytes = encrypt(input);
            String passw=new String(encryptionBytes);
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionURL, "root", "root");
PreparedStatement ps = con.prepareStatement("INSERT INTO user(name,password,address,telno) VALUES(?,?,?,?)");
ps.setString(1,name);
ps.setString(2,passw);
ps.setString(3,address);
ps.setInt(4,ph);
int i = ps.executeUpdate();
ps.close();

}
catch(Exception ex){
System.out.println(ex);
}
try{
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from user where id='1'");
String str="";
if(rs.next()){
str=rs.getString("password");
}
out.println("Your password is: "+decrypt(str.getBytes()));
System.out.println("Your password is: "+decrypt(str.getBytes()));
}
catch(Exception e){}
%>

For the above code, we have create a database table:

CREATE TABLE `user` (                                     
          `id` bigint(255) NOT NULL auto_increment,               
          `name` varchar(255) default NULL,                       
          `password` varchar(255) default NULL,                   
          `address` varchar(255) default NULL,                    
          `telno` int(255) default NULL,                          
          PRIMARY KEY  (`id`)                                     
        );









Related Tutorials/Questions & Answers:
Decrypt an encrypted password in JSP
Decrypt an encrypted password in JSP   How to decrypt an encrypted password and store in database ? Her is my code that i have done for encryption..."); > String > pass=request.getParameter("password"); > String > cpass
decrypt a password in servlet
decrypt a password in servlet  hi i want to decrypt the password.when user log in take the encrypted password and decrypt .then check the password with user entered and log in to the system
Advertisements
spring hibernate encrypted password
In this section, you will learn about encrypted password in spring hibernate
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password  Hi, I need the functionality in JSP to encrypt the password while inserting into DB and need decrypt logic while
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password  Hi, i encrypt password and stored in to DB.but i dont know decrypt that password.plz send the code.in your site link
JSP code for forget password
JSP code for forget password  I need forget password JSP code.. example http://www.roseindia.net/users/forgotpassword.html
forgot password code in jsp
forgot password code in jsp  forgot password code in jsp   Please visit the following link: http://www.roseindia.net/jsf/richfaces
change password - JSP-Servlet
a simple web application using mysql and jsp. now i want to create a web page for a user. this web page consists of changing the password for the existing user. it look like this: current password new password confirm new password SUBMIT
Encrypt Password with JSP - JSP-Servlet
Encrypt Password with JSP  Hi guys... I need you help.... I want to ask you how to make encrypt password with JSP servlet. For example I have form registration consists of: username, password, retype password, fullname, telp
Change Password - JSP-Servlet
Change Password  Hi all, Please kindly help me with jsp code and explanations to enable me write a change password program. This program will connect to mssql database 2000. Thanks
default password Allow the user to see the typed alphanumeric or character before it is changed to an encrypted dot
default password Allow the user to see the typed alphanumeric or character before it is changed to an encrypted dot  Allow the user to see the typed alphanumeric or character before it is changed to an encrypted dot in xsl n
Password History - JSP-Servlet
Password History  I am using servlets and in my application i want to maintain password history.It means on password change My application should check previous 5 password so that new password can't be same to 5 old password
Java swing store the encrypted password into database
Java swing store the encrypted password into database In this tutorial, you will learn how to encrypt the password and insert it into database. Here.... When the user enters the password field, the value is first encrypted
how to change password into one jsp to another jsp
how to change password into one jsp to another jsp  i have two jsps in one jsp i give one password and confirm password, in another jsp i want change my password compare with 1st jsp how to write code please give me answer?  
Decrypt - Java Beginners
Decrypt  How can I modify the file such that the user can enter a cipher text(encrypted) message and a key and my program will decrypt the message. import javax.swing.*; public class Cesar { private String plainText
code for password strength using jsp-servlet
code for password strength using jsp-servlet  hi.............. plz help me to give code for password strength using jsp-servlet for implementation in my project as soon as possible because i want to show this functionality in my
Send forgot Password through mail - JSP-Servlet
Send forgot Password through mail   hello every one I am designing a admin login page where i am validating the password through file(Example if user Name is Sreenivas and types sree as password i check a file where i
Change Password Code in JSP
Change Password Code in JSP In this example we will see how to change password code in jsp. First of all we have created a form where we have displayed...;/head> <h2 align="center"><strong>Change password in JSP
can any one give the frogort password code using jsp,
can any one give the frogort password code using jsp,  plz give the code for frogot password
Password encryption and decryption
it in database? and then call back the encrypted password to let the user login??   ... in order to submit the details into database. The password is first encrypted... then you can use the decrypt function, created in the jsp. 1)form.jsp: <
change password servlets - JSP-Interview Questions
change password servlets  hi all, i need the codes to create a change password servlet.  Hi, I dont have the time to write the code. But i... a link for change the password page in that page there should be a three text box
Password
Password  make a program which ask ask the username and password * in this format. in C language
AES Decryption using key password
AES Decryption using key password    /* Decrypt using AES...;  /* Decrypt using AES with password */ /* developed by Nishanth...="; // password to decrypt 16 bit final static String strPassword
jsp login code ... when username , drop down box and password is correct
jsp login code ... when username , drop down box and password is correct  i need a jsp code for login.... when username password and dropdown box...; var password=document.form.pass.value; if(username==""){ alert("Enter Username
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... in dropdown box.... so when i login i all the three username,password and dropdown box...=document.form.user.value; var password=document.form.pass.value; if(username==""){ alert("Enter
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... in dropdown box.... so when i login i all the three username,password and dropdown box...=document.form.user.value; var password=document.form.pass.value; if(username
Random Creation of password
details in it.When clicking on the submit button it gives me a password .....Details and the password is saved in the database....The password has to be encrypted and then send to the database.....I am using jsp as my front end and java
how to check username & password from database using jsp
how to check username & password from database using jsp  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
password protected zip file creation exmpale coded neaded - JSP-Servlet
password protected zip file creation exmpale coded neaded  am able to create a zip file and able to read the file but password protection need please help
ModuleNotFoundError: No module named 'andotp-decrypt'
ModuleNotFoundError: No module named 'andotp-decrypt'  Hi, My... named 'andotp-decrypt' How to remove the ModuleNotFoundError: No module named 'andotp-decrypt' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'cisco_decrypt'
ModuleNotFoundError: No module named 'cisco_decrypt'  Hi, My... 'cisco_decrypt' How to remove the ModuleNotFoundError: No module named 'cisco_decrypt' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'msoffice-decrypt'
ModuleNotFoundError: No module named 'msoffice-decrypt'  Hi, My... named 'msoffice-decrypt' How to remove the ModuleNotFoundError: No module named 'msoffice-decrypt' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pcf_decrypt'
ModuleNotFoundError: No module named 'pcf_decrypt'  Hi, My Python... 'pcf_decrypt' How to remove the ModuleNotFoundError: No module named 'pcf_decrypt' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'pcf_decrypt'
ModuleNotFoundError: No module named 'pcf_decrypt'  Hi, My Python... 'pcf_decrypt' How to remove the ModuleNotFoundError: No module named 'pcf_decrypt' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'pybd-decrypt'
ModuleNotFoundError: No module named 'pybd-decrypt'  Hi, My Python... 'pybd-decrypt' How to remove the ModuleNotFoundError: No module named 'pybd-decrypt' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pywe-decrypt'
ModuleNotFoundError: No module named 'pywe-decrypt'  Hi, My Python... 'pywe-decrypt' How to remove the ModuleNotFoundError: No module named 'pywe-decrypt' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'andotp-decrypt'
ModuleNotFoundError: No module named 'andotp-decrypt'  Hi, My... named 'andotp-decrypt' How to remove the ModuleNotFoundError: No module named 'andotp-decrypt' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'cisco_decrypt'
ModuleNotFoundError: No module named 'cisco_decrypt'  Hi, My... 'cisco_decrypt' How to remove the ModuleNotFoundError: No module named 'cisco_decrypt' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'humilis-decrypt'
ModuleNotFoundError: No module named 'humilis-decrypt'  Hi, My... named 'humilis-decrypt' How to remove the ModuleNotFoundError: No module named 'humilis-decrypt' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pcf_decrypt'
ModuleNotFoundError: No module named 'pcf_decrypt'  Hi, My Python... 'pcf_decrypt' How to remove the ModuleNotFoundError: No module named 'pcf_decrypt' error? Thanks   Hi, In your python environment
Java Encryption using AES with key password
Java Encryption using AES with key password    /* AES alogrithm using password key */ /* developed by Nishanth Thomas Insolutions Global Pvt... - password, IV = keyBytes - password*/ public class testencrypt
sir plz help in design a jsp page whichis as follow username [_____] select [__>]password [_____] after selection then onlypassword text box is visible
sir plz help in design a jsp page   sir plz help in design a jsp page which is as follow username [ _ ] select [ > ] password [ _ ] after selection then only password text box is visible
Forgot Password of Application
Forgot Password of Application  Forgot Password of Application through servlet and jsp
forget password
forget password  can i get coding for forgot password in jsp, need using javamail also cannot.. what should i do?? Thx
Version of com.pddstudio>encrypted-preferences dependency
List of Version of com.pddstudio>encrypted-preferences dependency
ModuleNotFoundError: No module named 'tensorflow-encrypted'
ModuleNotFoundError: No module named 'tensorflow-encrypted'  Hi...: No module named 'tensorflow-encrypted' How to remove the ModuleNotFoundError: No module named 'tensorflow-encrypted' error? Thanks   Hi
ModuleNotFoundError: No module named 'tf-encrypted'
ModuleNotFoundError: No module named 'tf-encrypted'  Hi, My Python... 'tf-encrypted' How to remove the ModuleNotFoundError: No module named 'tf-encrypted' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'encrypted_bigquery'
ModuleNotFoundError: No module named 'encrypted_bigquery'  Hi, My... named 'encrypted_bigquery' How to remove the ModuleNotFoundError: No module named 'encrypted_bigquery' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'encrypted-config'
ModuleNotFoundError: No module named 'encrypted-config'  Hi, My... named 'encrypted-config' How to remove the ModuleNotFoundError: No module named 'encrypted-config' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'encrypted-dns'
ModuleNotFoundError: No module named 'encrypted-dns'  Hi, My... 'encrypted-dns' How to remove the ModuleNotFoundError: No module named 'encrypted-dns' error? Thanks   Hi, In your python