Click here to Skip to main content
15,886,919 members
Home / Discussions / Java
   

Java

 
PinnedForum Guidelines - PLEASE READ Pin
Chris Maunder28-Jul-09 2:36
cofounderChris Maunder28-Jul-09 2:36 
QuestionMy java output is running but the output does not follow assignment format Pin
Olivia824-Mar-24 20:18
Olivia824-Mar-24 20:18 
AnswerRe: My java output is running but the output does not follow assignment format Pin
OriginalGriff24-Mar-24 20:24
mveOriginalGriff24-Mar-24 20:24 
QuestionJava assignmnent due tonigh!! error message "Index 1 out of bounds for length 1" Pin
Olivia824-Mar-24 6:23
Olivia824-Mar-24 6:23 
AnswerRe: Java assignmnent due tonigh!! error message "Index 1 out of bounds for length 1" Pin
OriginalGriff24-Mar-24 6:28
mveOriginalGriff24-Mar-24 6:28 
GeneralRe: Java assignmnent due tonigh!! error message "Index 1 out of bounds for length 1" Pin
Olivia824-Mar-24 10:11
Olivia824-Mar-24 10:11 
GeneralRe: Java assignmnent due tonigh!! error message "Index 1 out of bounds for length 1" Pin
OriginalGriff24-Mar-24 20:19
mveOriginalGriff24-Mar-24 20:19 
GeneralRe: Java assignmnent due tonigh!! error message "Index 1 out of bounds for length 1" Pin
jschell26-Mar-24 12:03
jschell26-Mar-24 12:03 
AnswerRe: Java assignmnent due tonigh!! error message "Index 1 out of bounds for length 1" Pin
jimakoskx24-Mar-24 22:30
jimakoskx24-Mar-24 22:30 
GeneralSecurity Manager gone Pin
jschell20-Mar-24 12:52
jschell20-Mar-24 12:52 
Questionlarge numbers Pin
mike741114-Jan-24 12:58
mike741114-Jan-24 12:58 
AnswerRe: large numbers Pin
Pete O'Hanlon14-Jan-24 20:47
mvePete O'Hanlon14-Jan-24 20:47 
AnswerRe: large numbers Pin
Richard MacCutchan14-Jan-24 21:42
mveRichard MacCutchan14-Jan-24 21:42 
QuestionPlease help me with this password validation - While Loop Running Once Pin
R1s1ng Phoen1x14-Jan-24 4:35
R1s1ng Phoen1x14-Jan-24 4:35 
I am tryint to validate a password that has the following rules: can't be the same as username, at least 8 characters, and must have a uppercase letter and special character. Any help you can offer would be AMAZING! Smile | :)

import java.util.Scanner;


public class Main {
    static String userName = "johndoe";
    static String password = "ABC_1234";
    static boolean validPassword = false;

    public static void main(String[] args) {
        System.out.println("Please Change Your Password");

        System.out.println("""
                Please make sure it is 8 characters long,
                Contains an uppercase letter,
                Contains a special character,
                Does not contain your username,
                And is not the same as the previous password
                """);

        checkPassword();
    }

    public static void checkPassword() {
        System.out.println();
        System.out.print("What is your new password? ");
        Scanner scanner = new Scanner(System.in);
        String newPassword = scanner.next();
        //System.out.println(newPassword);

        while (!validPassword) {
            if (newPassword.equalsIgnoreCase(userName)) {
                System.out.println("Your password can't be the same as your username");
                System.out.print("What is your new password? ");
                newPassword = scanner.next();


            }
            if (newPassword.length() < 8) {
                System.out.println("You password must be at least 8 characters");
                System.out.print("What is your new password? ");
                newPassword = scanner.next();
                //validPassword = true;
            }
            for (int i = 0; i < newPassword.length(); i++) {
                char ch = newPassword.charAt(i);
                if (!Character.isUpperCase(ch) || (Character.isDigit(ch) && Character.isLetter(ch) && Character.isWhitespace(ch))) {
                    System.out.println("Please make sure your password has an uppercase and/or special character");
                    newPassword = scanner.next();
                    validPassword = true;
                } else {
                    System.out.println("stop");
                    validPassword = false;
                }
            }
        }
    }
}


modified 14-Jan-24 10:51am.

AnswerRe: Please help me with this password validation - While Loop Running Once Pin
Richard MacCutchan14-Jan-24 5:15
mveRichard MacCutchan14-Jan-24 5:15 
GeneralRe: Please help me with this password validation - While Loop Running Once Pin
R1s1ng Phoen1x14-Jan-24 5:58
R1s1ng Phoen1x14-Jan-24 5:58 
GeneralRe: Please help me with this password validation - While Loop Running Once Pin
Richard MacCutchan14-Jan-24 6:06
mveRichard MacCutchan14-Jan-24 6:06 
AnswerRe: Please help me with this password validation - While Loop Running Once Pin
Gerry Schmitz14-Jan-24 5:19
mveGerry Schmitz14-Jan-24 5:19 
GeneralRe: Please help me with this password validation - While Loop Running Once Pin
R1s1ng Phoen1x14-Jan-24 5:59
R1s1ng Phoen1x14-Jan-24 5:59 
Questionviewing Java disassembly Pin
mike741111-Jan-24 22:55
mike741111-Jan-24 22:55 
AnswerRe: viewing Java disassembly Pin
Richard MacCutchan11-Jan-24 23:22
mveRichard MacCutchan11-Jan-24 23:22 
GeneralRe: viewing Java disassembly Pin
jschell12-Jan-24 10:13
jschell12-Jan-24 10:13 
GeneralRe: viewing Java disassembly Pin
Richard MacCutchan12-Jan-24 22:09
mveRichard MacCutchan12-Jan-24 22:09 
AnswerRe: viewing Java disassembly Pin
jschell12-Jan-24 10:14
jschell12-Jan-24 10:14 
GeneralRe: viewing Java disassembly Pin
mike741112-Jan-24 10:25
mike741112-Jan-24 10:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.