Daily Coding Challenge - P@ssw0rd Str3ngth!

This is my code segment:

import re

# Function to check password strength

def password_strength(password):

    n = len(password)
    check1 = (n >= 8)
    check2 = re.search("[A-Z]",password) and re.search("[a-z]",password)
    check3 = re.search("[0-9]", password)
    check4 = re.search("[@#$%^&*!]", password)

    checks = [check1, check2, check3, check4]
    check_count = 0

    for check in checks:
        if (check):
           check_count += 1 
           # print("[AFTER FOR LOOP Check_Count]: [check_count] = [%d]" % (check_count))

    if (check_count < 2):       
       return "weak"
    elif (check_count >= 2 and check_count < 4): # [2,3]
       return "medium"
    elif (check_count >= 4):
       return "strong"
    else:
       return "n/a" 

I just tested it and MY Compiler says it’s good to go by comparing expected output of resultant function calls to the actual. Python. Is your compiler doing without the re module?

How do we compare the specific RegEx values then?

I moved your message to a new topic, please always create your own topic for your questions, do not ask in someone else’s topic

are you sure your compiler say that your code is correct? half of the code is not inside the function

@ILM. Noted.

This is the full compiler output:

[spoiler]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [1, 123456, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [2, pass!!!, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [3, Qwerty, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [4, PASSWORD, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [5, PASSWORD!, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[AFTER FOR LOOP Check_Count]: [check_count] = [3]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [6, PassWord%^!, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [3]
[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [7, qwerty12345, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [8, PASSWORD!, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[AFTER FOR LOOP Check_Count]: [check_count] = [4]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [9, S3cur3P@ssw0rd, strong]

[AFTER FOR LOOP Check_Count]: [check_count] = [4]
[AFTER FOR LOOP Check_Count]: [check_count] = [4]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [10, C0d3&Fun!, strong]

[AFTER FOR LOOP Check_Count]: [check_count] = [4]
isSameListContents = True

[/spoiler]

This kind of pretentiousness is a contributing factor to hating this forum rather than AI.
Sycophant v. CompTIA Wannabe with self-righteous tendencies…

are you sure you shared the right code? the for loop and if statement are not inside the function in the code you shared. A compiler would give an error with a return outside a function.


I am not sure I understand, what pretentiousness are you talking about? We can only comment on the code you share. The code you shared does not compile.

  File "<string>", line 23
SyntaxError: 'return' outside function

… The code functions just fine. The aliasing problem of your directory fails its compilation on web server because it’s not operant under an Object-Oriented Context, but rather a strictly method function call perspective aliased as a standalone function. ‘password_strength_checker.py‘

The above may not have bearing on the specific issue at hand, but outlines the macroscopic points at large just fine.

Your argument is the following:

”Default Dead Pub-Sub AS Strictly No Reply Dead Comment Admin only”

I did not know that return can be used outside a function, what kind of environment are you using?

and how are you referring to the function parameter from outside the function?

it may be a part of python I have no experience with. Do you have docs to share?

are you treating me like a bot or something?

Is this NOT Auto-rendered using Web Application AI Toolkits over WebSocket Layering TLS/SSL Over IPSec AWS Encryption?

the python is executed in the browser using pyodide https://pyodide.org/

Method Execution Context CAN allow for direct method calls, hence, when I’m testing externally on a global context, that the return debug output shows up in duplicity rather than a strict execution.

Moreover, the code is partially formatted improperly by the Markdown Language Syntactic Compiler. The Indentation Level of the above code block in NEW[1/12] is partly incorrect in formatting, due to indentation error.

The For-Each loop is at the same level as the instantiated local variables. Shifted to account for the indentation level, it Compiles in a strictly method call context.

You only need the first 23-ish lines. The rest is external compiler debug code for error checking and validation.

if I cut to line 23, it’s the line with return "weak", I am not sure of what code you are talking about, if I do that, even adjusting the indentation, it would never return medium or strong

also, if you put the code in a codeblock, it will have the right indentation

please share the code, so we have the same code in front

also reminder, the starting code is

def check_strength(password):

    return password

Above New[1/12] is *Correctly* formatted to match method block function call relative to indentation level.

Matching FULL Code is the following:

import re
# Function to check password strength
def password_strength(password):
    n = len(password)
    check1 = (n >= 8)
    check2 = re.search("[A-Z]",password) and re.search("[a-z]",password)
    check3 = re.search("[0-9]", password)
    check4 = re.search("[@#$%^&*!]", password)
    checks = [check1, check2, check3, check4]
    check_count = 0
    for check in checks:
        if (check):
           check_count += 1 
    
    print("[AFTER FOR LOOP Check_Count]: [check_count] = [%d]" % (check_count))
    if (check_count < 2):       
       return "weak"
    elif (check_count >= 2 and check_count < 4):
       return "medium"
    elif (check_count >= 4):
       return "strong"
    else:
       return "n/a" 

# Test Password Samples
test_passwords = ["123456", "pass!!!", "Qwerty", "PASSWORD", "PASSWORD!", "PassWord%^!", "qwerty12345", "PASSWORD!", "S3cur3P@ssw0rd", "C0d3&Fun!"]

# Call the function and display the result
count = 0
expected_password_strengths = []
asserted_password_strengths = ["weak", "weak", "weak", "weak", "medium", "medium","medium", "medium", "strong", "strong"]
for password in test_passwords:
    count += 1
    print("[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [%d, %s, %s]\n" % (count, password, password_strength(password)) )
    expected_password_strengths.append(password_strength(password))

print("isSameListContents = {}".format(expected_password_strengths == asserted_password_strengths))

thank you!

did you take a moment to confront with the starting code?

or with the test cases that are failing?

check_strength("123456") should return "weak" .

No Artificial Intelligence would have Clooney Levels of Smug. You made your point that both of us are in the wrong.

Here is MY Compiler Output:

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [1, 123456, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [2, pass!!!, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [3, Qwerty, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [4, PASSWORD, weak]

[AFTER FOR LOOP Check_Count]: [check_count] = [1]
[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [5, PASSWORD!, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[AFTER FOR LOOP Check_Count]: [check_count] = [3]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [6, PassWord%^!, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [3]
[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [7, qwerty12345, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [8, PASSWORD!, medium]

[AFTER FOR LOOP Check_Count]: [check_count] = [2]
[AFTER FOR LOOP Check_Count]: [check_count] = [4]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [9, S3cur3P@ssw0rd, strong]

[AFTER FOR LOOP Check_Count]: [check_count] = [4]
[AFTER FOR LOOP Check_Count]: [check_count] = [4]
[FOR PASSWORD TEST LOOP]: [count, password, password_strength] = [10, C0d3&Fun!, strong]

[AFTER FOR LOOP Check_Count]: [check_count] = [4]
isSameListContents = True

did you miss my last message?

if you call check_strength("123456"), what happens?

Please stop insulting the person trying to help you.

I’m deleting this thread and discontinuing my activity to this forum henceforth.

You want to lie about what was provided, that’s on you…

As you did not try to call the function I suggested, let me be explicit, you have the wrong function name

what was a lie?