# 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! ๐
#๐ Python Username/Password Checker not working
53 messages ยท Page 1 of 1 (latest)
@robust granite
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.
Closes after a period of inactivity, or when you send !close.
You didn't say what isn't working.
Also, we'll help fix your code, but we won't write the code for you.
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
What was the username you wrote?
I tried the profanity thing with username ABC. I didn't get the profanity trigger
I DONNO CHECK OUT THE VID
This doesnt show you entering the username at all
Nevermind still an issue
Share your latest code in a pastebin please
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.
How do I i did, now
Read the embed message โ๏ธ
thanks
So this is a lot clearer now. Thanks
As I said, your video doesn't show you entering your username so I don't know why it skipped to entering the password
How do I clear my terminal?
When I tried exactly your code, the username does trigger profanity properly
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
This is what I'm getting. But I think its just because of how you're doing things inside a while loop
Did you put in the entire code?
What version of Python are you using?
I'm using 3.12.3
On VSCODE
yes
The code works from 3+
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
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
You have to pay attention to your indents of your while loops
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
Like? can you show me?
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
Give me 10 minutes, I will be back with new codebase
Im gonna take a shower. Take your time
Crazy
Is it?
Also I really like the blood round font in this site. What is the name of the font?
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.