View Single Post
Join Date: Nov 2008
Posts: 2
Reputation: AsantaSane is an unknown quantity at this point 
Solved Threads: 0
AsantaSane AsantaSane is offline Offline
Newbie Poster

Basic Password Verifier

 
0
  #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.


  1. import java.util.Scanner;
  2.  
  3. public class PasswordVerifier
  4. {
  5. public static boolean isValid(String userPass)
  6. {
  7. /**
  8. * This is the default stored password
  9. */
  10.  
  11. // Password stored by default is "cool"
  12.  
  13. boolean goodSoFar = true; // Flag
  14. int index = 0; // Loop control variable
  15.  
  16. // Is the string the correct length?
  17. if (userPass.length() != 4)
  18. goodSoFar = false;
  19.  
  20.  
  21. // Test to see if the characters match the password
  22. while (goodSoFar && index < 4)
  23. {
  24. if (!Character(userPass.charAt(index == 'c')))
  25. goodSoFar = false;
  26. index++;
  27. if (!Character(userPass.charAt(index == 'o')))
  28. goodSoFar = false;
  29. index++;
  30. if (!Character(userPass.charAt(index == 'o')))
  31. goodSoFar = false;
  32. index++;
  33. if (!Character(userPass.charAt(index == 'l')))
  34. goodSoFar = false;there
  35. index++;
  36.  
  37. //results are returned
  38. return goodSoFar;
  39. }
  40. }
  41. }


And then here is my driver class


  1. import java.util.Scanner;
  2.  
  3. public class PasswordDriver
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. PasswordVerifier PW = new PasswordVerifier();
  9. String user; // To hold a user pass
  10.  
  11.  
  12. while(user != "")
  13. {
  14. System.out.println("Please enter a password containing letters and lowercase only, or nothing to end");
  15. //create a scanner object
  16. Scanner keyboard = new Scanner(System.in);
  17.  
  18. //get user pass
  19. user = keyboard.nextLine();
  20.  
  21. //Determine if the password is valid.
  22. if (PW(user))
  23. {
  24. System.out.println("That is a valid password");
  25. }
  26. else
  27. {
  28. System.out.println("That is not the proper password or format");
  29. System.out.println("Here is an example: cool");
  30. }
  31. }
  32. }
  33. }




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!
Reply With Quote