Home Answers Viewqa Development-process Java store username and encrypted password in database

 
 


kirankumar
Java store username and encrypted password in database
1 Answer(s)      a year ago
Posted in : Development process

how to a program such that i want to store username and encrypted password in database and when i retreive from database i should get username and decrypted password. plz im waiting for ur reply. thank in advance.

View Answers

May 5, 2012 at 11:44 AM


The given code will allow the user to enter username and password. This password is then encrypted and insert into the database along with username. If you user want to get the encrypted password in its decrypted form then you can easily get it from the database.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.security.*;
import javax.crypto.*;

class Login extends JFrame implements ActionListener
{
    JButton SUBMIT;
 JPanel panel;
 JLabel label1,label2;
 final JTextField  text1,text2;
    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;
          }

  Login()
  {
  label1 = new JLabel();
  label1.setText("Username:");
  text1 = new JTextField(15);

  label2 = new JLabel();
  label2.setText("Password:");
  text2 = new JPasswordField(15);

  SUBMIT=new JButton("SUBMIT");

  panel=new JPanel(new GridLayout(3,1));
  panel.add(label1);
  panel.add(text1);
  panel.add(label2);
  panel.add(text2);
  panel.add(SUBMIT);
  add(panel,BorderLayout.CENTER);
  SUBMIT.addActionListener(this);
  }
 public void actionPerformed(ActionEvent ae)
  {
     try{

String uname=text1.getText();
String pass=text2.getText();

 key = KeyGenerator.getInstance(algorithm).generateKey();
            cipher = Cipher.getInstance(algorithm);
            String input = pass;
            byte[] encryptionBytes = encrypt(input);
            String passw=new String(encryptionBytes);
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection con=null;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionURL, "root", "root");
PreparedStatement ps = con.prepareStatement("INSERT INTO login(username,password) VALUES(?,?)");
ps.setString(1,uname);
ps.setString(2,passw);
int i = ps.executeUpdate();
ps.close();


Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from login where username='"+uname+"'");
String str="";
if(rs.next()){
str=rs.getString("password");
}
JOptionPane.showMessageDialog(null,"Your password is: "+decrypt(str.getBytes()));
}
catch(Exception e){}
}

  public static void main(String arg[])throws  Exception
  {
  try
  {
  Login frame=new Login();
  frame.setSize(300,100);
  frame.setVisible(true);
  }
  catch(Exception e)
  {JOptionPane.showMessageDialog(null, e.getMessage());}
  }
}









Related Pages:
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...; users(username,password,lastname,email,phone,gender,firstname,confirm_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 is an example that creates two fields to accept username and password from the user
Username password
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...=st.executeQuery("select * from login where username='"+value1+"' and password='"+value2
validating username and password from database
validating username and password from database  Hello sir, i am developing a login page. i want that when i fill data in text fields. it validate data from database. if enter data is match from database. page goes to next page
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section, you will come to know how to read username, password and port no from... = prop.getProperty("username"); String pass = prop.getProperty("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... that requires user to login to enter the system. so I wanted to store encrypted
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
store and retrive image from database - JDBC
an image in database using java?  Hi friend, Code for store image in database using Java. import java.sql.*; import java.io.*; public class..."; String userName = "root"; String password = "root"; Connection con = null
spring hibernate encrypted password
In this section, you will learn about encrypted password in spring hibernate
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  //this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  //this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
how can we store the encrypted passwaord in swings?
how can we store the encrypted passwaord in swings?   how can we store the encrypted passwaord in swings
Random Creation of 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... to generate a random password and insert into database... Please help me out
to enter into a particular page only if the username,password and listbox value mtches
to enter into a particular page only if the username,password and listbox value... in to his page only if the username, password and the listbox value(user type) matches using "jsp".where the username,password,user type are stored in a single table
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
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
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password)
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password)   myself muthu,am working as software trainee in reputed concern.our company gave one project to me.create
How to store image into database
into database using Java. Can anyone help me that how can i store image into database using Java. Thanks in advance.   hi friend, To store image into the database the data type blob can be used and in the Java code you can use
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password) 0 Answer(s)
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password) 0 Answer(s)  create webpage... username and password
To store date - JSP-Servlet
.....   Hi friend, Code to store date in database...("com.mysql.jdbc.Driver"); con = DriverManager.getConnection(url+dbName,userName,password...To store date  Hai friends, I want the format to store
Password
Password  make a program which ask ask the username and password * in this format. in C language
how to store image upload path to mssql database
the file path to database. 1)form.jsp: <%@ page language="java" %> <...how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use
how to store image upload path to mssql database
the file path to database. 1)form.jsp: <%@ page language="java" %> <...how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use
how to store image upload path to mssql database
the file path to database. 1)form.jsp: <%@ page language="java" %> <...how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use
how to store image upload path to mssql database
the file path to database. 1)form.jsp: <%@ page language="java" %> <...how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
javascript ( username and password )  pls can nyone give me a code to write and read the login details (username and password )into a xml file using javascript. (XML database
to store data entered in html page
use two forms for it 1)for user name,password, submit button 2)for text field,reset and submit botton in form 1 after entering username and password by clicking...to store data entered in html page  i want to a job site
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
Mysql Permission
; Mysql Permission allows the user to connect to the database, Mysql checks and use that the particular username/ password and combination has... to access the listed table in database of local host. The password is specified
Forgot Password Screen of Application
to the if it exists in the database. User's password is retrieved from database... Password link, the "Access Your Username and password" screen... Password Screen: If the user enters wrong username or email address
Softabar Password Manager
, is encrypted using AES encryption algorithm. Store accounts... Softabar Password Manager       Softabar Password Manager is an easy way to manage
login-password - Java Beginners
login-password  complete code of login-password form then how...){ if(theForm.userid.value==""){ //Please enter username alert("Please enter User Name...; } if(theForm.password.value==""){ //please enter passward alert("Please enter Password
How can I protect my database password ?
How can I protect my database password ?   How can I protect my database password ? I'm writing a client-side java application that will access..., where the connection string to the database, including user and password, is stored
Password - Java Beginners
charecter just as typing password in E-mail.ID without using applet... can we do...("Username")); rowOne.add(new JTextField(20)); Box rowTwo = Box.createHorizontalBox(); rowTwo.add(new JLabel("Password")); rowTwo.add(new
Spring Security Password Hashing
text which is susceptible to attack. So, it is advised don't store password... username\ /\ password login.jsp <%@ taglib prefix="c" uri="..._username.focus();'> <h3>Login with Username and Password (Custom Page)<
How To Store Image Into MySQL Using Java
how to store an image into the database using Java and MySQL. This example... characters. To store the image into database using Java we will be required... using Java. We will use the MySQL database system to store the image
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
change password - JSP-Servlet
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(a submit button) now this current password is already in the database named
for store data in data base - JSP-Servlet
= request.getParameter("userName"); String password = request.getParameter...for store data in data base  i want to a job site, in this site user... three form for it 1)for user name and password.. 2)for personal detail... 3
windows username - JSP-Servlet
windows username  how to reset the password and username of windows using jsp
Connecting to a MySQL Database in Java
Connecting to a MySQL Database in Java   ... in the database with the help of java,  instead of going to database... to connect the MySQL database with the Java file. Firstly, we need to establish
Java Xml Data Store
Java Xml Data Store  I have to do this project and i'm finding it so... be followed up and/or purchased. You will need to store the data in a local binary or XML file. As a good Java programmer you will use correct Object-Oriented
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.