RSS Forums RSS

Basic Password Verifier

Please support our Java advertiser: Programming Forums
Reply
Posts: 2
Reputation: AsantaSane is an unknown quantity at this point 
Solved Threads: 0
AsantaSane AsantaSane is offline Offline
Newbie Poster

Basic Password Verifier

  #1  
Nov 18th, 2008
Hey there, this is my first post here and I'm in the need of some real help.


I've written a basic password verifier, which checks to see if what you type in is the same as the default stored password, but i continually get a compile error.


import java.util.Scanner;

public class PasswordVerifier
{
	public static boolean isValid(String userPass)
		{
			/**
			 * This is the default stored password
			 */
			
			// Password stored by default is "cool"
			
			boolean goodSoFar = true; // Flag
			int index = 0;				  // Loop control variable
			
			// Is the string the correct length?
			if (userPass.length() != 4)
				goodSoFar = false;
				
				
			// Test to see if the characters match the password
			while (goodSoFar && index < 4)
			{
				if (!Character(userPass.charAt(index == 'c')))
					goodSoFar = false;
				index++;
				if (!Character(userPass.charAt(index == 'o')))
					goodSoFar = false;
				index++;
				if (!Character(userPass.charAt(index == 'o')))
					goodSoFar = false;
				index++;
				if (!Character(userPass.charAt(index == 'l')))
					goodSoFar = false;there 
				index++;
			
			//results are returned
			return goodSoFar;
		}
}
}
			


And then here is my driver class


import java.util.Scanner;
 
public class PasswordDriver
{

public static void main(String[] args)
{
	PasswordVerifier PW = new PasswordVerifier();
	String user; // To hold a user pass
	
	
	while(user != "")
		{
			System.out.println("Please enter a password containing letters and lowercase only, or nothing to end");
			//create a scanner object
			Scanner keyboard = new Scanner(System.in);
			
			//get user pass
			user = keyboard.nextLine();
			
			//Determine if the password is valid.
			if (PW(user))
				{
					System.out.println("That is a valid password");
				}
			else
				{
					System.out.println("That is not the proper password or format");
					System.out.println("Here is an example: cool");
				}
		}
}
}




The error i get when I'm compiling is

PasswordVerifier.java:30: charAt(int) in java.lang.String cannot be applied to (boolean)
if (!Character(userPass.charAt(index == 'c')))
^
PasswordVerifier.java:33: charAt(int) in java.lang.String cannot be applied to (boolean)
if (!Character(userPass.charAt(index == 'o')))
^
PasswordVerifier.java:36: charAt(int) in java.lang.String cannot be applied to (boolean)
if (!Character(userPass.charAt(index == 'o')))
^
PasswordVerifier.java:39: charAt(int) in java.lang.String cannot be applied to (boolean)
if (!Character(userPass.charAt(index == 'l')))



could someone please help me out, i've tried multiple variances and fixes, but alas... none work for me. Thanks everyone!
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Basic Password Verifier

  #2  
Nov 18th, 2008
it needs to be changed to this format
if (userPass.charAt(index) == 'c')

but you are making it hard, you can do this
if(userPass.startsWith("cool")){
return false;
}
Custom Application & Software Development
www.houseshark.net
Reply With Quote  
Posts: 644
Reputation: sillyboy is on a distinguished road 
Solved Threads: 54
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Basic Password Verifier

  #3  
Nov 18th, 2008
startsWith? so "coolblahblahblah" will be true too? not sure that sounds totally secure, but yeah, the compiler error is as stated above.
Reply With Quote  
Posts: 1,158
Reputation: javaAddict is just really nice javaAddict is just really nice javaAddict is just really nice javaAddict is just really nice 
Solved Threads: 163
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Veteran Poster

Re: Basic Password Verifier

  #4  
Nov 18th, 2008
I think you have misplaced the parenthesis:

This:
if (!Character(userPass.charAt(index == 'c')))

Should be:
if (!Character(userPass.charAt(index) == 'c'))

You could also try:
goodSoFar = userPass.equals("cool");
return goodSoFar;
There are 3 ways to do things:
The right way, the wrong way,
And The Object Oriented Way.

When you do things your way, make sure you don't forget the Object Oriented Way
Reply With Quote  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Basic Password Verifier

  #5  
Nov 18th, 2008
lol i don't think checking if the password contains c o o l, was too secure, thats why i made the post
Custom Application & Software Development
www.houseshark.net
Reply With Quote  
Posts: 2
Reputation: AsantaSane is an unknown quantity at this point 
Solved Threads: 0
AsantaSane AsantaSane is offline Offline
Newbie Poster

Re: Basic Password Verifier

  #6  
Nov 18th, 2008
thanks dickersonka... that fixed the compile issue for the constructor, but in the drive i'm now getting the following error, yet i see nothing wrong =\


symbol : method PW(java.lang.String)
location: class PasswordDriver
if (PW(user))
Reply With Quote  
Posts: 644
Reputation: sillyboy is on a distinguished road 
Solved Threads: 54
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Basic Password Verifier

  #7  
Nov 18th, 2008
You already have the "PasswordVerifier" so you now want to use the methods within it.

PW.isValid(user)
Reply With Quote  
Posts: 705
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 83
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Basic Password Verifier

  #8  
Nov 19th, 2008
wow ... and to think I thought the .equals(..) method worked great
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Java Forum
Views: 633 | Replies: 7 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:58 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC