r/CodingForBeginners • • Oct 31 '26

Pseucodecode check?

Did some pseudocode for something due tomorrow concerning arrays. would like to know if my logic concerning arrays is skewered. It's formatted the way it is due to the teacher's preference lol/

Problem

Search the web to discover 10 commonly used passwords and store them in an array. Write pseudocode to represent the logic of a program that prompts a user for a password, then displays an error message and continues to prompt until the user has not chosen one of the common passwords.

CODE:

START

 

//HOUSEKEEPING

DECLARE USER_PASSWORD

DECLARE COMMON_PASSWORDS[10]

DECLARE INDEX

DECLARE MATCH_FOUND

 

SET COMMON_PASSWORDS[0] = "123456"

SET COMMON_PASSWORDS[1] = "password"

SET COMMON_PASSWORDS[2] = "qwerty"

SET COMMON_PASSWORDS[3] = "111111"

SET COMMON_PASSWORDS[4] = "12345678"

SET COMMON_PASSWORDS[5] = "123456789"

SET COMMON_PASSWORDS[6] = "admin"

SET COMMON_PASSWORDS[7] = "abc123"

SET COMMON_PASSWORDS[8] = "123123"

SET COMMON_PASSWORDS[9] = "iloveyou"

 

//INPUT

DISPLAY "Enter a password:"

INPUT USER_PASSWORD

 

//PROCESS

SET MATCH_FOUND = TRUE

 

WHILE MATCH_FOUND = TRUE

 

SET MATCH_FOUND = FALSE

 

FOR INDEX = 0 TO 9

 

IF USER_PASSWORD = COMMON_PASSWORDS[INDEX] THEN

SET MATCH_FOUND = TRUE

ENDIF

 

ENDFOR

 

IF MATCH_FOUND = TRUE THEN

DISPLAY "ERROR: Password is too common. Please enter a different password:"

INPUT USER_PASSWORD

ENDIF

 

ENDWHILE

 

//OUTPUT

 DISPLAY "Password accepted."

END

3 Upvotes

9 comments sorted by

View all comments

1

u/BoOmAn_13 Nov 01 '26

It's good for the requirements given. My own input would be instead of use "magic values" 0-9 for your loop, try a for each iterator or a length method. You know the size of the list already so it's not very important, but sometimes it's easier to work with seeing "this code goes over item in a list" vs "this loop gets the first 10 values of a list, so what do we do if we want to make the list large later on?"

I missed the part where it needed to be 10 the first time I looked at would have suggested trying out a file read operation on the rockyou.txt word list, but no, your code does what you need it to do, and it from what I see, it does it right.

Edit: maybe it's just me my I'd prefer to get input at the start of the loop, so input is collected once, and at the end of the loop you print the error and repeat