aspose file tools*
The moose likes Java in General and the fly likes Password verification program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Password verification program" Watch "Password verification program" New topic
Author

Password verification program

sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141


Well,
Since a longtime I am trying to get my PAssword verification program work but it always fails the check
I am wondering what are other ways to compare the user entered string to the original string.
here is the program I am using
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
//import java.io.*;
/*<applet<br /> code=Login.class<br /> width=800<br /> height=150>
</applet>*/
public class Login extends Applet implements ActionListener {
String s;
TextField usernm,passwd;
Button enter;
public void init(){

usernm= new TextField(80);
add(usernm);
passwd= new TextField(80);
add(passwd);
enter= new Button("Enter");
add(enter);
enter.addActionListener(this);
}


public void actionPerformed(ActionEvent event){

if (event.getSource()==enter)
{
//now compare this username agaisnt the list of users and their passwords
String msg="hehe";
s=String(passwd);
if ((s.equals(msg)))
{
System.out.println("Entered");//have t introduce a link to another window:like a triggerin VB

}
else
{System.out.println("Caught Redhanded"+msg);

}
}
}
}
please help !!!

"Learning is weightless, a treasure you can always carry easily." -Chinese Proverb
Pratap Reddy
Ranch Hand

Joined: Jan 05, 2001
Posts: 36
Instead of using s=String(passwd); use s = passwd.getText();
Then it should work fine.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Since this question has nothing to do with certification, I am moving this thread to
Java in General(intermediate)
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141

Thanks Pratap and others
,please take a look at following code also
I am Modifying the program a bit to accomaodate the PassWordField
here the program is giving an error as undefined variable or a class name s1 however s1 is completely defined as a String object
then how to debug the code I know that the o/p of a password field can be retrieved by getPassword method but this returns the value in char.then a new probelem has crept up as to how to compare a char with a String that is entered in the password field
please help!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Login3
{ public static void main(String args[])
{
JFrame frame=new EntryScreen();
frame.show();
}
}
class EntryScreen extends JFrame implements ActionListener
{
public EntryScreen()
{
setSize(300,200);
setTitle("Login");
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e) //is initialising
{
System.exit(0);
}
} );
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout()); ///vvvvip line
JPanel canvas=new JPanel();
contentPane.add(canvas,"Center");
JPanel p=new JPanel();
JTextField name=new JTextField(15);
contentPane.add(name,"Center");
JPasswordField pass=new JPasswordField(15);
contentPane.add(pass);
JButton submit=new JButton("Submit");
submit.addActionListener(this);
contentPane.add(submit);

}//entry screen
public void actionPerformed(ActionEvent ae)
{
//String s1=pass.getText();
// String t=new String("hehe");
if(s1.equals(t))
{ System.out.println("INSide");
}
else
{System.out.println("nothing");
}

}}
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
I think the problem now is that the JPasswordField() variable 'pass' is out of scope. If you uncomment the two lines in your actionedPerformed method and then declare the pass variable in the top of your EntryScreen class (making it an instance variable), it should work. Something like this

I hope this helps.
Sean
sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141

Thanks Sean,for giving a try It feels good to have you by my side.
I tried your method but strangly it is giving error as undefined variable or classname pass
Well,getText method is also deprecated for JPasswordField whic is the warning issued by the javac command
I am posting my findings about it,See if it gives you an Idea
JPasswordField
getPassword
public char[] getPassword()
Returns the text contained in this TextComponent. If the underlying document is null, will give a NullPointerException. For stronger security, it is recommended that the returned character array be cleared after use by setting each character to zero.
Can any one give an example of using this
JPasswordField pass=new JPasswordField(15);
contentPane.add(pass);
...
....
public void actionPerformed(ActionEvent ae)
{
String s1=pass.getPassword();
String t=new String("hehe");
if(s1.equals(t))
{ System.out.println("INSide");
-------
}
else
{System.out.println("nothing");
-----
}
complete code below //

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Login3
{ public static void main(String args[])
{
JFrame frame=new EntryScreen();
frame.show();
}
}
class EntryScreen extends JFrame implements ActionListener
{
public EntryScreen()
{
setSize(300,200);
setTitle("Login");
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e) //is initialising
{
System.exit(0);
}
} );
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout()); ///vvvvip line
JPanel canvas=new JPanel();
contentPane.add(canvas,"Center");
JPanel p=new JPanel();
JTextField name=new JTextField(15);
contentPane.add(name,"Center");
JPasswordField pass=new JPasswordField(15);
contentPane.add(pass);
JButton submit=new JButton("Submit");
submit.addActionListener(this);
contentPane.add(submit);

}//entry screen
public void actionPerformed(ActionEvent ae)
{
String s1=pass.getPassword();
String t=new String("hehe");
if(s1.equals(t))
{ System.out.println("INSide");
}
else
{System.out.println("nothing");
}

}}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Password verification program