#๐Ÿ”’ Python Username/Password Checker not working

53 messages ยท Page 1 of 1 (latest)

robust granite
#

# Take user input for username and password.


while True:

    username = input ("USERNAME: ")

    if profanity.contains_profanity(username.lower()): 
        print ("Your username cannont contain any profanity or obsceneity!")
    
    else:
        break
    

# Security Checks for Password.

    while True:

        password = input ("PASSWORD: ")
        print ("-"*50)
        errors = []


        if len(password) <10:
        errors.append("Your password must be at least 10 chracters long!")

        if not any (char.isdigit() for char in password):
        errors.append("Password must contain at least one digit!")

        if not any (char.isupper() for char in password):
        errors.append("Password must contain at least one uppercase character!")

        if not any (char.islower() for char in password):
        errors.append("Password must contain at least one lowercase character!")

        special_characters = "!@#$%^&*()-_=+[]{}|;:'\",.<>?/`~"

        if not any (char in special_characters for char in password):
        errors.append("Password must contain at least one special character!")

        if not errors:
            print (username)
            print (password)
            break

        else:
            for e in errors: 
                print ("-", e)

    

# Minimal length must be 10 characters.
# Password must contain digits.
# Password must contain upper and lower case alphabets.
# Password must contain special characters. ```

Need help with code. Want to check username for profanity firstโ€”loop until valid. Then do the same for password. Only move forward when both are clean. Please include comments in the code. Thanks! ๐Ÿ˜Š
sharp marshBOT
#

@robust granite

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

valid ravine
robust granite
#

Even if I enter the right username and password, for some reason it tells me my username contains profanity, and sends me back to write my username

true pendant
robust granite
#

"ABC" and pssword "01912257318Ab@"

#

Can I send you a video of me writing it?

true pendant
#

I tried the profanity thing with username ABC. I didn't get the profanity trigger

robust granite
#

I DONNO CHECK OUT THE VID

true pendant
robust granite
#

Wait I fouind the issue

#

Indentation

#

SHIT

true pendant
#

๐Ÿคทโ€โ™‚๏ธ

robust granite
#

Nevermind still an issue

true pendant
sharp marshBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

robust granite
true pendant
robust granite
true pendant
#

thanks

true pendant
true pendant
# robust granite

As I said, your video doesn't show you entering your username so I don't know why it skipped to entering the password

robust granite
#

How do I clear my terminal?

true pendant
#

When I tried exactly your code, the username does trigger profanity properly

robust granite
#

How do I send you the terminal messege? How do I copy the messege in the terminal, perhaps it can help you understand and debug

true pendant
#

This is what I'm getting. But I think its just because of how you're doing things inside a while loop

robust granite
#

Did you put in the entire code?

#

What version of Python are you using?

#

I'm using 3.12.3

#

On VSCODE

true pendant
true pendant
true pendant
# robust granite

Oh ok you forget to stop the while loop. Hit CTRL + C a couple of times

#

In the terminal

#

Then rerun your code

#

You should consider putting these inside functions with def

robust granite
#

So now another problem.

If I put it the correct username, it just ask for my username again, but if I put profanity, it tells me I can't, and than takes me to the password input, instead of taking me back to the username input. Than if I get the password wrong, tells me to put it again, if it's right, it displays it.

First, why is it taking me back and asking for my username, when it doesn't contain profanity, but when I add a username with profanity, it tells me "Your username cannont contain any profanity or obsceneity!" but takes me to the password input. I want i so if I enter proifanity username, it tells me "Your username cannont contain any profanity or obsceneity!" and takes me to the suername input, and until I put a username without profanity, than it will ask me for password, and same with the password, until I get my password right, it will keep asking me, and telling me the issues, until I get it right and after than I want the code to end

true pendant
#

Your username while loop also contains a while loop for password

#

Its clearer and easier if you put these while loops inside functions, then you can call each function as and when you need them

robust granite
#

Like? can you show me?

true pendant
#

e.g.

def set_username():
  while True:
    username = input("Username: ")
    # put your profanity and other checks here
    ...
    return username # if all checks passes, return the username

def set_password():
  while True:
    password = input("Password: ")
    # put all of your if statements to check password length and such here
    return password # if all checks passes, return the password

def setup_user_credentials():
  username = set_username()
  password = set_password()
  print(f"Your new username is {username}")
  print(f"Your new password is {password}")
  

Something like that

robust granite
#

Give me 10 minutes, I will be back with new codebase

true pendant
#

Im gonna take a shower. Take your time

wicked rivet
#

Crazy

true pendant
#

Is it?

robust granite
#

Also I really like the blood round font in this site. What is the name of the font?

sharp marshBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.