Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


RoseletPraveen
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
1 Answer(s)      3 years and 11 months ago
Posted in : JSP-Servlet


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.


Advertisement
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
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
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
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
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 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
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 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
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
Developing Forgot Password Form
Developing Forgot Password Form       In this section we will develop Forgot Password Form code for our application. Developing Forgot Password Form  
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
Forgot Password Screen of Application
Forgot Password Screen of Application       Forgot Password Screen our web application allows... is displayed. With the help of this screen user can retrieve their password.  Forgot
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
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
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
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
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
How to threow timeout exception when DB is not responding
How to threow timeout exception when DB is not responding  How to throw timeout exception when DB is not responding
How to threow timeout exception when DB is not responding
How to threow timeout exception when DB is not responding  How to throw timeout exception when DB is not responding
Advertisements
 

 

 

DMCA.com