Creating a program that asks for a password and checks if its correct or not

write a function that checks whether a string is a valid password python
java program to check valid password
java program to check password strength
python password checker loop
java code for password validation
how to verify a username and password in python
username and password in java code
password validation in java without regular expression

this is some practice i am doing for my midterm tomorrow. I cant seem to find the problem with my code, this is the question:

Having a secure password is a very important practice, when much of our information is stored online. Write a program that validates a new password, following these rules:

• The password must be at least 8 characters long.

• The password must have at least one uppercase and one lowercase letter

• The password must have at least one digit.

Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid.

Here is the code:

import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author HP Laptop
 */
public class PasswordValidation {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Please enter password : ");
        String password = in.nextLine();
        System.out.print("Please re-enter the password to confirm : ");
        String confirm = in.nextLine();
        boolean condition;
        condition = isValid(password);
        while (!password.equals(confirm) && (!condition)) {
            System.out.println("The password is invalid");
            System.out.print("Please enter the password again : ");
            String Password = in.nextLine();
            System.out.print("Please re-enter the password to confirm : ");
            String Confirm = in.nextLine();


        }
        if (isValid(password)) {
            System.out.println("The password is valid");
        /*} else {
            System.out.println("The password is not valid");
            System.out.print("Please enter the password again : ");
            String Password = in.nextLine();
            System.out.print("Please re-enter the password to confirm : ");
            String Confirm = in.nextLine();
        }*/
    }
    }

    public static boolean isValid(String password) {

        if (password.length() < 8) {
            return false;
        } else {

        for (int i = 0; i < password.length(); i++) {
            if (Character.isUpperCase(password.charAt(i))) {
            }
        }


        for (int b = 0; b < password.length(); b++) {
            if (Character.isLowerCase(password.charAt(b))) {
            }
        }

        for (int c = 0; c < password.length(); c++) {
            if (Character.isDigit(password.charAt(c))) {
            }

        }

        return true;


    }
}
}

Error is:

I enter a name less than 8 digits and it would say its valid when its not, also when its all valid and right, it doesn't print that its valid.

@user3821797: I slightly modified your isValid method. Go through it and make sure you understand what I did. If you have any questions at all, please comment here and I'll help you out.

    public static boolean isValid(String password) {
    Boolean atleastOneUpper = false;
    Boolean atleastOneLower = false;
    Boolean atleastOneDigit = false;

    if (password.length() < 8) { // If its less then 8 characters, its automatically not valid
        return false;
    }

    for (int i = 0; i < password.length(); i++) { // Lets iterate over only once. Saving time
        if (Character.isUpperCase(password.charAt(i))) {
            atleastOneUpper = true;
        }
        else if (Character.isLowerCase(password.charAt(i))) {
            atleastOneLower = true;
        }
        else if (Character.isDigit(password.charAt(i))) {
            atleastOneDigit = true;
        }
    }

    return (atleastOneUpper && atleastOneLower && atleastOneDigit); // Return true IFF the password is atleast eight characters long, has atleast one upper, lower and digit
}

Java Method Exercises: Check whether a string is a valid password, Write a Java method to check whether a string is a valid password. is valid: " + s); } else { System.out.println("Not a valid password: " + s); }  A Program to check if strings are rotations of each other or not; How to validate a Password using Regular Expressions in Java; Program to check if a number belongs to a particular base or not; Program to check if first and the last characters of string are equal; Python program to check if a string is palindrome or not; Program to check for a

There might be a few issues here, but the one that stands out is this:

while (!password.equals(confirm) && (!condition)) {

If I type the password "abc" and confirmation as "abc", then !password.equals(confirm) is false. I think you want this to be:

while (!password.equals(confirm) || (!condition)) {

Because you want to repeat this behavior whenever the password doesn't match or is invalid.

This is also incorrect:

    condition = isValid(password);
    while (!password.equals(confirm) && (!condition)) {
        System.out.println("The password is invalid");
        System.out.print("Please enter the password again : ");
        String Password = in.nextLine();
        System.out.print("Please re-enter the password to confirm : ");
        String Confirm = in.nextLine();
    }

You never re-check isValid, and you're storing the re-entered password and confirmation in new variables (scoped to the loop) called Password and Confirm. Try assigning these directly to your existing variables and re-calling isValid:

    condition = isValid(password);
    while (!password.equals(confirm) && (!condition)) {
        System.out.println("The password is invalid");
        System.out.print("Please enter the password again : ");
        password = in.nextLine(); // <-- HERE
        System.out.print("Please re-enter the password to confirm : ");
        confirm = in.nextLine(); // <-- HERE

        condition = isValid(password); // <-- HERE
    }

C# Password Check Exercise - C#, Can you please email the full solution code for the C# Password Checker exercise, otherwise I cannot continue. You can always copy your code first to make a back-up. if using System; namespace PasswordChecker { class Program { public static void Not sure why you're asking, but you are correct. Contribute your code and comments through Disqus. Previous: Write a C program to check if two numbers in a pair is in ascending order or descending order. Next: Write a C program to read the coordinate(x, y) (in Cartesian system) and find the quadrant to which it belongs (Quadrant -I, Quadrant -II, Quadrant -III, Quadrant -IV).

instead of

while (!password.equals(confirm) && (!condition)) {

you want

while (!password.equals(confirm) || (!condition)) {

Since the password is invalid if either isValid(password) returned false, or the confirmed password is different than the original typed password.

Your current code won't pass the while condition if password.equals(confirm), even though condition is false (due to the password being to short).

In addition, your while loop should call condition = isValid(password); again after the password and confirmed password are re-typed. Otherwise, the while loop would never exit.

So either write :

    condition = isValid(password);
    while (!password.equals(confirm) || (!condition)) {
        System.out.println("The password is invalid");
        System.out.print("Please enter the password again : ");
        String Password = in.nextLine();
        System.out.print("Please re-enter the password to confirm : ");
        String Confirm = in.nextLine();
        condition = isValid(password);
    }

Or more elegantly :

    while (!password.equals(confirm) || !isValid(password)) {
        System.out.println("The password is invalid");
        System.out.print("Please enter the password again : ");
        String Password = in.nextLine();
        System.out.print("Please re-enter the password to confirm : ");
        String Confirm = in.nextLine();
    }

Program to check Strength of Password, A password is said to be strong if it satisfies the following criteria: It contains at least one Given a string, find its strength. Let a strong CPP program to check if a given password is. // strong or not. #include hasLower = true ;. if ( isupper  Python program to check the validity of a Password. In this program, we will be taking a password as a combination of alphanumeric characters along with special characters, and check whether the password is valid or not with the help of few conditions. Primary conditions for password validation : Minimum 8 characters.

I have checked above code and went through small modification and have tested over it and it is not accepting the password with less than 8 digits.And no need to add more variables. Go through it..

condition = isValid(password);
    while (!password.equals(confirm) && (!condition)) {
        System.out.println("The password is invalid");
        System.out.print("Please enter the password again : ");
        String Password = in.nextLine();
        System.out.print("Please re-enter the password to confirm : ");
        String Confirm = in.nextLine();
        password = Password;
        confirm = Confirm;
        condition = isValid(password);
   }

Python program to check the validity of a Password, In this program, we will be taking a password as a combination of alphanumeric and check whether the password is valid or not with the help of few conditions. Python program to take user input and check the validity of a password : In this tutorial, we will learn how to check the validity of a user input password in python. The user will enter one password and our program will check if it is valid or not. If not valid, it will ask the user to re-enter the password.

Username and password login java project, Too many while loops, and the expression on the last one is wrong, it should be: Hide Copy Code. // use && as both expressions need to be  • The password must be at least 8 characters long. • The password must have at least one uppercase and one lowercase letter. • The password must have at least one digit. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again.

Digital Design for Computer Data Acquisition, On the other hand, if the 74373 Q's are wrong, it's necessary to thoroughly evaluate the Connect oscilloscope channel 1 via a test clip to the 74138's pin 4​. If not, save the program, turn the power off, remove the ports circuit from the The strategy here is to establish one signal which definitely works and build from there. From what I see, this is the single most common reason that your email program repeatedly asks for your password. First, check the CAPS LOCK key on your keyboard. That’s often the cause — you think you’re typing in “AReallyGreatPassword”, when in fact you’re typing in “arEALLYgREATpASSWORD”, which is most certainly not the same thing.

The Python Workbook: A Brief Introduction with Exercises and Solutions, (27 Lines) In this exercise you will create a function named nextPrime that finds and The value of n will be passed to the function as its only parameter. Display the randomly generated password in your file's main program. Your main program should only run when your solution has not been imported into another file. How to Input Password in C ? [crayon-5ec0ca807b521508050004/] Output : [crayon-5ec0ca807b52d420106201/] Explain ? [crayon-5ec0ca807b531861548880/] Accept Character without Echo [ without displaying on Screen ] getch will accept character and store it in “ch” [crayon-5ec0ca807b536540913033/] ASCII Value of “Enter Key” is 13 Stop Accepting Password Characters after “Enter” Key.

Comments
  • What are those 3 for loops doing?
  • @GPRathour checking each condition.
  • Did you try debugging it?
  • condition is an icky variable name.
  • user3821797: as GPRathour and @Dave Newton have pointed out, I believe if your style was neater then you'd have a much easier time debugging this code. I suggest you name variable names more useful and have many small functions that each do a very specific task.
  • thank you my friend, but now if its valid it wont print valid, it prints invalid.
  • I suggest you look at this line "while (!password.equals(confirm) && (!condition))". I believe you want "||" instead of "&&". You want to tell them their password is incorrect if what they entered does not match what they confirmed OR if what they entered it not valid.
  • right, thanks it worked but still now i enter a correct password, it says its incorrect.
  • Updated for the second issue :)
  • worked thank you, now when i enter a correct password it says invalid
  • @user3821797 Edited the answer.
  • @user3821797 What password did you enter? Did you enter the same password twice?