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 is there but code is not displayed.plz help me.

View Answers

January 19, 2011 at 5:57 PM

Hi Friend,

Try this:

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`)                                     
        );

Thanks









Related Tutorials/Questions & Answers:
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
Advertisements
forgot password?
forgot password?  forgot password
Forgot password
Forgot password  hi i want to develop a code for when user clicks on forgot password then the next page should be enter his mobile no then the password must be sent to his mobile no...! Thanks in advance Nag Raj
coding for forgot password
coding for forgot password  coding for forgot password
Forgot Password of Application
Forgot Password of Application  Forgot Password of Application through servlet and jsp
Forgot Password of Application
Forgot Password of Application  i want sample code for Forgot Password of Application
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
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
Simple Java applet that need usernam, password and textfield.
Simple Java applet that need usernam, password and textfield.  Hi. Anyone can help me on this matter: I need to create a small application that require user to login by username and password. After login, they should meet
while Append need a new line for column and row
while Append need a new line for column and row  HI While using append in javascript for retreiving the rows and its column header, its retreiving but after column header i need new line but it is not coming. Thanks in advance
Coding for forgot password
Coding for forgot password  coding for forgot password   Please go through the following links: http://www.roseindia.net/jsf/richfaces/ http://www.roseindia.net/struts/hibernate-spring/ Here you will find a jsf
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
forgot password - Struts
forgot password  i want to proper code for forgot password, means how to send password into email id if i forgot my password   import java.io.*; import javax.mail.*; import javax.mail.internet.*; // important
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
encrypt the username and password using PHP
encrypt the username and password using PHP  How can we encrypt the username and password using PHP?   Hi friends, You can use the MySQL PASSWORD() function to encrypt username and password. For example, INSERT
Developing Forgot Password Form
Developing Forgot Password Form       In this section we will develop Forgot Password Form code for our application. Developing Forgot Password FormADS_TO_REPLACE_1
Forgot Password Screen of Application
Forgot Password Screen of Application       Forgot Password Screen our web application allows... on the Forgot Password link, the "Access Your Username and password"
Send forgot Password through mail - JSP-Servlet
Send forgot Password through mail   hello every one I am... is provided) Now my question is how do i send the password if admin click on forgot password and i need to send that password through mail after answering a few
Forgot Password Action,Struts Forgot Password Action class
Forgot Password Action       Forgot Password Action The password forgot Action is invoked when you forgot your password and want to recover the password. The forgot
How can we encrypt the username and password using PHP?
How can we encrypt the username and password using PHP?  How can we encrypt the username and password using PHP
Password
Password  make a program which ask ask the username and password * in this format. in C language
forget password
forget password  can i get coding for forgot password in jsp, need using javamail also cannot.. what should i do?? Thx
Exception while inserting image in oracle using java
Exception while inserting image in oracle using java  import java.sql.*; import java.io.*; class Oracle2 { public static void main(String args[])throws Exception { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am... 1month, I am facing one issue which is like: One of my thread get struct while inserting/updating to database. I dont know what is the issue but it was never
error while inserting millions of records - EJB
error while inserting millions of records  Hello, I am using ejb cmp and inserting 1 millions of records but it won't work because trancation time out occurs same problem is occur when i am using hibernate but when i am using
getting error while inserting values in database
getting error while inserting values in database  AddUser.java import java.io.*; import java.sql.*; import javax.servlet.*; import...) { out.println("An Error Had occurred while accessing the database
need
need  i need a jsp coding based project plz help me
Records are not inserting in to main table while running the mysql stored procedure.
Records are not inserting in to main table while running the mysql stored procedure.  Hi, Im migrating procedures from oracle to MySql.In... me with this issue. My Code: BEGIN select concat('Inserting into SD
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... and then saved into database. We have used DES algorithm to encrypt and decrypt
SQLGrammarException while trying to save data in db
SQLGrammarException while trying to save data in db  //hibernate cfg file// <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN
Authentication of password - Swing AWT
Authentication of password  System level authentication of password.... How the Printed password gets converted into the asteric (*) mark... String: " + inputStr); System.out.println("Encrypt code: " + str1
while and do while
while and do while  hello, What is the difference between a while statement and a do statement?   hello,ADS_TO_REPLACE_1 A while statement checks at the beginning of a loop to see whether the next loop iteration
secure password
secure password   Respected Sir We need to write a function which accepts a given password and returns ââ?¬Å?ACCEPTEDââ?¬Â? or ââ?¬Å?REJECTEDââ?¬Â? based on the following rules: Passwords must consist of a mixture
secure password
secure password   Respected Sir We need to write a function which accepts a given password and returns ââ?¬Å?ACCEPTEDââ?¬Â? or ââ?¬Å?REJECTEDââ?¬Â? based on the following rules: Passwords must consist of a mixture
password check
password check  how to check sighup passowrd and login password
JSP code for forget password
JSP code for forget password  I need forget password JSP code.. example http://www.roseindia.net/users/forgotpassword.html
Username password
that will validate usernames and passwords from a database. I need help with the validation, so that if the username and password match it will continue... that checks whether the username and password is valid or not. If the user
change password
change password  how to change password in the login form.... by giving options to user like this old password, new password.. pls help
Reset Password
Reset Password  coding for reset password
retype password
retype password  coding for retype password
need to ans abt db - JSP-Servlet
need to ans abt db  helllo can you tell me m just starting to knowing abt servlet and i trying to making e-mail site so can you tell me with the java servlet wht is the backhand database to use to proper with that site
Password encryption and decryption
. Is there anyway that you could teach me how to encrypt the password and store..."); } out.println("Your password is: "+decrypt(str.getBytes())); System.out.println("Your password is: "+decrypt(str.getBytes())); } catch(Exception e){} %>
While and do-while
While and do-while       Nested classes Here is another advantage of the Java, object... The advantage of a static nested class is that it doesn't need an object
Excel Password Cracker Software
Excel Password Cracker Software  Hello I just want to know what is Excel Password Recovery software? I want need to recover a worksheet since I forgotten
make a file password protected
make a file password protected  I am trying to write Java code for creating a file of any type (either text,csv,or any other format). What I need is : The file generated should be zipped and password-protected. When I try to open
forget password?
forget password?  can anyone help me? how to create a module of forget password?the password can reset by generate random password and send to user's email..i develop the php system using xampp and dreamweaver
forget password?
forget password?  can anyone help me? how to create a module of forget password?the password can reset by generate random password and send to user's email..i develop the php system using xampp and dreamweaver
forget password
forget password  codding for forget password using spring framework
PHP While Loop
While Loop in PHP: In programming language we need to use loops for executing... are used namely for, while and do while. Apart from these there are some loops... tutorial we will study while, do while and for. ADS_TO_REPLACE_1 So let's get

Ads