Important alert: (current site time 6/20/2013 1:03:13 AM EDT)
 

VB icon

Password Detection

Email
Submitted on: 6/27/2012 8:57:00 AM
By: Creator_1493  
Level: Beginner
User Rating: By 1 Users
Compatibility: Java (JDK 1.1), Java (JDK 1.2), Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 1411
(About the author)
 
     This is a password detection software and basically detects whether you have enter a right password or not, with extra functionality with which you can also set your own password(when starting application for first time,please make sure hit enter key after typing the password to activate the buttons).

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Password Detection
// Description:This is a password detection software and basically detects whether you have enter a right password or not, with extra functionality with which you can also set your own password(when starting application for first time,please make sure hit enter key after typing the password to activate the buttons).
// By: Creator_1493
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7038&lngWId=2//for details.//**************************************

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
class Pd{
JFrame frame = new JFrame("Test your password"); 
JButton set = new JButton("Set");
JButton check = new JButton("Check");
JLabel passwordLabel = new JLabel("Enter password : ");
JPasswordField passfield = new JPasswordField();
String password = "Creator1493";//current password , you can use any string to be your current password
String string = "INVALID";
Pd(){
	 frame.setVisible(true);
	 frame.setBounds(450, 270, 300, 250);
	 frame.setDefaultCloseOperation(1);
	 frame.setLayout(null);
	 
	 passwordLabel.setBounds(40, 10, 230, 35);
	 passfield.setBounds(40, 40, 200, 35);
	 passfield.setVisible(true);
	 passfield.setToolTipText("Enter password");
	 passfield.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
			set.setEnabled(true);
			check.setEnabled(true);
			}
		});
	 
 
	 set.setToolTipText("Click to set the password");
 set.setBounds(40, 130, 80, 40);
 set.setVisible(true);
 set.setEnabled(false);
 set.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
			String epass = JOptionPane.showInputDialog("Enter Current password");
			if(epass.equals(password)){
				String npass = JOptionPane.showInputDialog("Enter New password");
				password = npass;
				}
			else{
				JOptionPane.showMessageDialog(null, "Invalid Password try Again");
			}
			}
		});
 
 check.setToolTipText("Click to check the password");
 check.setBounds(150, 130, 80, 40);
 check.setVisible(true);
 check.setEnabled(false);
 check.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
			 	if(passfield.getText().toString().equals(password)){
			 		string = "VALID";
			 		JOptionPane.showMessageDialog(null,"Password is "+ string);
			 	}
			 	else{
			 		JOptionPane.showMessageDialog(null, "Invalid password" );
				}
			}
			});
 
 frame.add(set);
 frame.add(passwordLabel);
 frame.add(check);
 frame.add(passfield);	 
 }
 }
public class PasswordDetection{
	public static void main(String args[]){
	new Pd();
	}
}


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
8/27/2012 3:19:18 PMAmrit

There is an error
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.