| | |
Basic Password Verifier
![]() |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
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.
And then here is my driver class
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!
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.
Java Syntax (Toggle Plain Text)
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
Java Syntax (Toggle Plain Text)
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!
•
•
Join Date: Aug 2008
Posts: 1,158
Reputation:
Solved Threads: 136
it needs to be changed to this format
but you are making it hard, you can do this
Java Syntax (Toggle Plain Text)
if (userPass.charAt(index) == 'c')
but you are making it hard, you can do this
Java Syntax (Toggle Plain Text)
if(userPass.startsWith("cool")){ return false; }
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
startsWith? so "coolblahblahblah" will be true too? not sure that sounds totally secure, but yeah, the compiler error is as stated above.
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:
This:
if (!Character(userPass.charAt(index == 'c')))
Should be:
if (!Character(userPass.charAt(index) == 'c'))
You could also try:
Java Syntax (Toggle Plain Text)
goodSoFar = userPass.equals("cool"); return goodSoFar;
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Aug 2008
Posts: 1,158
Reputation:
Solved Threads: 136
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
www.houseshark.net
You already have the "PasswordVerifier" so you now want to use the methods within it.
Java Syntax (Toggle Plain Text)
PW.isValid(user)
![]() |
Other Threads in the Java Forum
- Previous Thread: getting errors in java for an assignment
- Next Thread: Sliding window protocol help
| Thread Tools | Search this Thread |
-xlint actionlistener add android applet application array automation bank bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse equation error event fractal ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper idea image infinite int j2me j2seprojects java javac javaee javame javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main method mobile myregfun netbeans notdisplaying number online pearl printf problem program qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows xor






