File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Check Password Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Check Password Program" Watch "Check Password Program" New topic
Author

Check Password Program

Stephen Son
Greenhorn

Joined: Dec 04, 2011
Posts: 14
This topic has been cross posted here.

Since I haven't been getting any replies on that topic, I figured I would post this same question on this site.

Some Websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rule is as follows:

  • A password must have at least 8 characters
  • A password consists of only letters and digits
  • A password must contain at least 2 digits


  • Write a program that prompts the user to enter a password and displays "Valid Password" if the rule is followed or "Invalid Password" otherwise.

    Here is my most up to date code:



    My code compiles and runs. The only part that isn't working is the part that checks to see if the password has at least 2 digits. How would I correct this?
    lokesh sree
    Ranch Hand

    Joined: Oct 27, 2009
    Posts: 99

    Hi,
    The check on count of digits(i.e, count<2 ) should happen once you have scanned through all the characters of your password i.e, after the for loop.
    You can actually step through each line for yourself and see why it's not working.


    Lokesh
    ( SCBCD 5, CCENT, SCJP 5 )
    Stephen Son
    Greenhorn

    Joined: Dec 04, 2011
    Posts: 14
    lokesh chenta wrote:Hi,
    The check on count of digits(i.e, count<2 ) should happen once you have scanned through all the characters of your password i.e, after the for loop.
    You can actually step through each line for yourself and see why it's not working.

    Oh I see. Thanks. I fixed that in my code.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38363
        
      23
    Stephen Son wrote:This topic has been cross posted here. . . .
    Welcome to the Ranch
    Thank you for telling us about the duplicate posting
    And you got an answer.
     
    wood burning stoves
     
    subject: Check Password Program