• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Check Password Program

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
     
    Ranch Hand
    Posts: 100
    Hibernate Eclipse IDE Java
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Stephen Son
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.
     
    Marshal
    Posts: 79179
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.
     
    Looky! I'm being abducted by space aliens! Me and this tiny ad!
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic