Hello, I'm developing a system that requires user to login to enter the system. so I wanted to store encrypted users' password in the database so that I wouldnt know their password. Is there anyway that you could teach me how to encrypt the password and store it in database? and then call back the encrypted password to let the user login??
May 7, 2012 at 12:49 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:
Password encryption and decryptionPassword encryption and decryption Hello, I'm developing a system... users'
password in the database so that I wouldnt know their
password. Is there anyway that you could teach me how to encrypt the
password and store
Advertisements
encryption and decryptionencryption and decryption ASCII encryptor
I want to develop a program that encrypt and decrypt. The messages stored in a file should.... This is called
encryption. When one wants to read the contents of the file
encryption and decryptionencryption and decryption ASCII encryptor
I want to develop a program that encrypt and decrypt. The messages stored in a file should.... This is called
encryption. When one wants to read the contents of the file
encryption and decryptionencryption and decryption ASCII encryptor
I want to develop a program that encrypt and decrypt. The messages stored in a file should.... This is called
encryption. When one wants to read the contents of the file
encryption and decryptionencryption and decryption ASCII encryptor
I want to develop a program that encrypt and decrypt. The messages stored in a file should.... This is called
encryption. When one wants to read the contents of the file
Encryption DecryptionEncryption Decryption I want to store a type string to my database, specifically MSSQL, I want the stored data in the database to be encrypted and I want to retrieve it in it's decrypted format.
I am using JSP's, I want
encryption and decryption of files encryption and
decryption of files Please can any one provide me with the code for
encryption and
decryption of files using RSA algorithm.
I want to use a browse option to search for the file which is needed for
encryption Encryption and Decryption - Java BeginnersEncryption and Decryption Hello sir,
i need
Password encryption and
decryption program using java program.
I dont know how to write the program... in databse.If a we will give the username and
password must check database encrypted
decryption and encryption - Java Beginnersdecryption and encryption hi everyone. my question is that i have one problem which i have to solve and the issue is that i have to do the
encryption and
decryption thing there in my code, e.g if the user enters the abc the code
servelt -jsp Encryption Decryption Codeservelt -jsp
Encryption Decryption Code
Encryption code&
Decryption code Iam developing a web security application for that reason i need a code of
encryption &
Decryption in servlet. Can u please send it to me.Its very
Encryption Decryption In Scriptlets/JavaEncryption Decryption In Scriptlets/Java I have this code in my scriptlet, when I use the
Encryption code to encrypt my data it executes... where the program stopped working and it stopped in the
decryption part and I get
encryption and decryption - Java Beginnersencryption and decryption i need files
encryption and
decryption program using java. but i dont know how to write the program.pls help me
thank you so much Hi Friend,
Try the following code:
import java.io.
AES Decryption using key password AES
Decryption using key
password /* Decrypt using AES with
password */
/* developed by Nishanth Thomas - Insolutions Global Pvt Ltd... String input = "sw0SrUIKe0DmS7sRd9+XMgtYg+BUiAfiOsdMw/Lo2RA=";
//
password Java Encryption using AES with key password Java
Encryption using AES with key
password /* AES alogrithm... This is my String";
//
password for
encryption
final static String strPassword...";
//
password for
encryption
final static String strPassword = "password12345678
AES decryption in Java AES
decryption in Java AES
decryption in Java with
password...-
Decryption-using-key-
password-.html
http://www.roseindia.net/answers/viewqa/Java-Beginners/26020-AES-
Decryption-using-key-
password-.html
PasswordPassword make a program which ask ask the username and
password * in this format.
in C language
Encryption In Swing - Swing AWTEncryption In Swing Hi sir i have a JFrame Containing User Name and
Password is there any way to encrypt
password and how can we store the encrypted passwaord to MS ACCESS
array password - Java Beginnersarray password i had create a GUI of
encryption program that used the array
password. my question is can we do the
password change program? i mean we change the older
password with the new
password sound encryptionsound encryption i want to ask if there is a simple code to perform
encryption on sound file
ModuleNotFoundError: No module named 'Encryption'ModuleNotFoundError: No module named '
Encryption' Hi,
My Python... '
Encryption'
How to remove the ModuleNotFoundError: No module named '
Encryption' error?
Thanks
Hi,
In your python environment you
password checkpassword check how to check sighup passowrd and login
password Encryption code - JSP-ServletEncryption code Iam developing a web security application for that reason i need a code of
encryption in servlet. Can u please send it to me.Its very urgent Because my project delivery date is very near
change passwordchange password how to change
password in the login form.... by giving options to user like this old
password, new
password.. pls help
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 passwordforget password codding for forget
password using spring framework
password changepassword change Hi ,
I am using jsf and trying to write a code to change the
password of a user .
Ihave to retrine userid fromdata base how to do that using session
Forgot passwordForgot 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
3D PASSWORD3D PASSWORD HI i would like to know abt where the 3d
password in india used and also few info about the 3d
password pls rply some1 as soon as possible
Password validationpassword and confirm
password are same or not Validation Hi. I have a change
password form. In that i have to check the values given in the new
password and confirm
password are same or not. Please help.
Here
Password validationPassword validation Hi. I have a change
password form. In that i have to check the values given in the new
password and confirm
password are same or not. Please help.
Here is a code that accepts the current
password Password validationPassword validation Hi. I have a change
password form. In that i have to check the values given in the new
password and confirm
password are same or not. Please help.
Here is a code that accepts the current
password Password validationPassword validation Hi. I have a change
password form. In that i have to check the values given in the new
password and confirm
password are same or not. Please help.
Here is a code that accepts the current
password Password validationPassword validation Hi. I have a change
password form. In that i have to check the values given in the new
password and confirm
password are same or not. Please help.
Here is a code that accepts the current
password forget passwordforget password can i get coding for forgot
password in jsp, need using javamail also cannot.. what should i do?? Thx
foget password is user login ,second is new user and third is forget
password in java using netbeans.so please help me to write the code for forget
password button.forget
password form have three field that is userid ,security question and answer of those
password - JDBCpassword as memeber of our site, recently he forget his
password now he want a new
password from us. so overcome with this problem i have to send his
password to his any emailid to once again login with this new pasword so
password - Securitypassword How can i do
password encript and decript in java Hi friend,
Code to encript and decript
password in java
import...
password= "Hello";
System.out.println("input " +
password Forget PasswordForget Password How i get my forget
password through mail?
Please visit the following links:
http://www.roseindia.net/jsf/richfaces/
http://www.roseindia.net/jsf/richfaces/developing-jsp-files.shtml