473,499 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Password problem help! URGENT!!!

10 New Member
I'm new to java and writing a program that accepts user input for a password and it has to meet the following requirements:
1. At least 6 characters long.
2. Leading character can't be a digit.
3. Password must have at least 1 digit.
4. Password must have at least 1 upper case letter.
The main method will keep asking the user for a password (using a while loop) until it gets one that's okay.
The other method has the signature:
public static boolean checkPassword (String word)
How do I write the while loop and checkPassword? PLEASE HELP!
Expand|Select|Wrap|Line Numbers
  1.  import java.util.Scanner;
  2.  
  3. public class Password
  4. {
  5.   public static void main (String[] args)
  6.   {
  7.     Scanner input;
  8.  
  9.     input = new java.util.Scanner(System.in);
  10.  
  11.      String pword = "";
  12.      boolean checkPassword;
  13.  
  14.      System.out.print("Please enter a new password:");
  15.      pword = input.nextLine();
  16.     while (checkPassword == false);
  17.     {
  18.       System.out.println("Your password does not meet the requirements!");
  19.  
  20.     }}
  21.   public static boolean checkPassword (String pword)
  22.   {
  23.     boolean bHasNUmeric = false;
  24.     boolean bHasUpper = false;
  25.  
  26.  
  27.  
Mar 27 '08 #1
1 1645
sukatoa
539 Contributor
I'm new to java and writing a program that accepts user input for a password and it has to meet the following requirements:
1. At least 6 characters long.
2. Leading character can't be a digit.
3. Password must have at least 1 digit.
4. Password must have at least 1 upper case letter.
The main method will keep asking the user for a password (using a while loop) until it gets one that's okay.
The other method has the signature:
public static boolean checkPassword (String word)
How do I write the while loop and checkPassword? PLEASE HELP!
Expand|Select|Wrap|Line Numbers
  1.  import java.util.Scanner;
  2.  
  3. public class Password
  4. {
  5.   public static void main (String[] args)
  6.   {
  7.     Scanner input;
  8.  
  9.     input = new java.util.Scanner(System.in);
  10.  
  11.      String pword = "";
  12.      boolean checkPassword;
  13.  
  14.      System.out.print("Please enter a new password:");
  15.      pword = input.nextLine();
  16.     while (checkPassword == false);
  17.     {
  18.       System.out.println("Your password does not meet the requirements!");
  19.  
  20.     }}
  21.   public static boolean checkPassword (String pword)
  22.   {
  23.     boolean bHasNUmeric = false;
  24.     boolean bHasUpper = false;
  25.  
  26.  
  27.  
Your while loop may led to infinite loop if checkPassword sets to false....
and also you have checkPassword method... Have you read your book?
Maybe you forgot it to implement it in the rightway.... Java is case sensitive...
Semicolon after while( \\\\\ ) is not necessary....

You are not initializing the Scanner to what stream shall it going to use for having the input value....

Expand|Select|Wrap|Line Numbers
  1. Scanner input = new Scanner(System.in);
Please, read carefully your book.... Doing so may avoid this kind of confusions....

Base on your code...
It prompts the user for password, since the condition might always true... You have to change the checkPassword into true if the input will be satisfied...

Here is the algo....

While ( Password is not satisfied ){
Prompt the user for password...
Check if it is allowable....
Compare the user's input to your choosen password.
If satisfied
Let the Password be satisfied
}

Update us,
sukatoa
Mar 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1271
by: IGotYourDotNet | last post by:
on my win 2000 server i'm starting to get an error aspnet_wp.exe could not be started. The error code for the failure is 80004005. This error can be caused when the worker process account has...
4
26459
by: kumar_ps | last post by:
i am new for vb6.0. i am using vb6.0 and msaccess. i have written following code for add new records to database table Private Sub Command1_Click() On Error Resume Next If Trim(Text2.Text) =...
2
2704
by: kumar_ps | last post by:
Hi, I am new for VB6.0 i need help urgent.. I have taken a picture box and a dialogbox for open when i click open dialog is showing bu how to open pdf files in the picturebox. and suppose we open a...
2
2284
by: kumar_ps | last post by:
Private Sub Command1_Click() On Error Resume Next If Trim(Text3.Text) = Trim(Text4.Text) Then rs.MoveFirst While Not rs.EOF If (Trim(Text1.Text) <> Trim(rs.Fields(0))) And...
2
341
by: situ | last post by:
Hi all, my system name is radx, and also my system log in name is radx, when i i tried to create user with name in manage user window , it show "system and username does not same". ok,...
1
2595
by: kommaraju | last post by:
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2 using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a error message of HTTP STATUS 500 my jdbc...
0
1070
by: vidhyapriya | last post by:
How do I Compress my Database with password (MS Access Database). Script Below was done if my database unlock with password protection, but when it lock... I've got an error : Cannot start your...
1
1206
by: =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?= | last post by:
Hello I've a huge problema with a asp.net page. my page has a user control that fires an event in that event handler I load a control property and update some text boxes accordingly. my...
2
1772
by: rKrishna2k6 | last post by:
We used to run our application on framework 1.1 and upgraded to 3.5 recently(I understood 2.0 and 3.5 are same except for the few add In s) Our Prod environment is on Win 2003 & IIS 6.0 and...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.