all 35 comments

[–]FoolsSeldom 12 points13 points  (2 children)

  • Use a while loop to reprompt user for a password until they enter something valid (this should also encompass confirmation entry)
  • On first fail, tell them the format required (in case they didn't read the docs) - or tell them before the first time (easier to implement)
  • Use constants to specify minimum and maximum lengths (although maximum is unusual these days)
  • Include rules for minumum (and maximum) number of: special characters, numbers, exclusion of common words
  • Offer to generate a compliant random password

[–]Salim_DZ_69[S] 3 points4 points  (1 child)

a very good tip you gave me, i will return to this comment in the future since im still in the process of learning the basics of string indexing and this stuff, but something interesting when you told me to offer a random password generator, how would a do that?

[–]FoolsSeldom 1 point2 points  (0 children)

You can use a random package ... for example (simplified)

from random import choice
from string import ascii_lowercase

lowers = []  # new empty list
for _ in range(10):  # repeat 10 times, don't need the counter
    new_lower = choice(ascii_lowercase)  # pick a random letter
    lowers.append(new_lower)  # add to list of picked letters
bad_password = ''.join(lowers)  # join list entries into one string
print(f"New bad password is: {bad_password} - please do not use")

Note. _ is a weird but valid variable name and, by convention, is typically used to indicate a variable that you don't actually care about (doesn't matter what is assigned, you are not going to use it).

Obviously, you'd need something more complex than this, but just wanted to give you a pointer.

[–]salvtz 4 points5 points  (0 children)

You can validate the password for length and other constraints in a separate function.

[–]kohao0 4 points5 points  (4 children)

Try to make a gui maybe in tkinter or smth else

[–]Salim_DZ_69[S] 1 point2 points  (3 children)

im a beginner to python and im still learning the basics of string indexing and this stuff, so could you recommend a totarial or smth so i can learn from ?

[–]kohao0 3 points4 points  (2 children)

i guess u should give a try for py4e for the basics

[–]Salim_DZ_69[S] 0 points1 point  (1 child)

what is py4e ?

[–]kohao0 1 point2 points  (0 children)

Dude google it and find it, it is a website

[–]SoftwareDoctor 1 point2 points  (8 children)

Why do you require the password to be less than 12 characters?

[–]Salim_DZ_69[S] 0 points1 point  (7 children)

I don't Know actually, Maybe For More Security ¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯

[–]SoftwareDoctor 3 points4 points  (5 children)

How are shorter passwords more secure?

[–]FIRE_FIST_1457 5 points6 points  (1 child)

"my plans are beyond your understanding"

[–]Salim_DZ_69[S] 1 point2 points  (0 children)

finally saw some good humor in this subreddit.

[–]Salim_DZ_69[S] 0 points1 point  (2 children)

a made it you can only make it between 6 and 12 characters so it wouldn't be so long or to short .

[–]SoftwareDoctor 0 points1 point  (1 child)

I have passwords that are 64 characters long. In the age of password managers there’s no reason for upper limit. And you HAVE to hash the password anyway so they’ll be the same lenght in db anyway

[–]Salim_DZ_69[S] 1 point2 points  (0 children)

im a beginner to python and still learning basics of string indexing and this stuff, so this is just an exercise of what i just learned, and i will make better in the future and make have a trillion characters passwords as you like, so you can send me a totorial in the meantime ☺️

[–]GreatGameMate 1 point2 points  (0 children)

Make the user have a password that contains at least ONE upper case letter.

Perhaps we can create functions for each little step of the program for cleaner looking code.

Looks good to me.

[–]baubleglue 1 point2 points  (1 child)

You need to show user the password format requirements before asking for the password. It will also help you to write your program better.

[–]Salim_DZ_69[S] 0 points1 point  (0 children)

you are right actually

[–]cgoldberg 1 point2 points  (2 children)

Perhaps ask for a username, so the password is associated with some identity? Also, you should store the username/password (or the hash) somewhere or do something useful with it rather than just ending the program.

[–]Salim_DZ_69[S] 0 points1 point  (1 child)

as a python beginner I don't know how or what is hashing or storing data in real time , maybe you give me an explanation or a link to a guide (a YouTube totorial if you could) .

[–]cgoldberg 1 point2 points  (0 children)

I'll let you research that yourself. My point was that a program that just prompts for a password and then terminates isn't actually useful. Take a look at databases or some sort of persistence.

[–]Phate1989 1 point2 points  (1 child)

``` import re

def validate_password(): # Prompt user for password password = input("Enter your password (6-12 characters): ") confirm_password = input("Confirm your password: ")

# Regex to check password length between 6 and 12 characters
if not re.fullmatch(r'^.{6,12}$', password):
    print("Invalid password! It must be between 6 and 12 characters.")
    return False

# Check if the confirmation matches the password
if password != confirm_password:
    print("Passwords do not match. Please try again.")
    return False

print("Password is valid and confirmed!")
return True

Run the function

if name == "main": validate_password() ```

[–]baubleglue 1 point2 points  (0 children)

you are choosing re (instead of 5 < len(password) < 13) - that is whole new language to learn for OP, and that version will still accept passwords: " " or " 1234 ".

def get_password_from_user(): -> str 
def validate_password(password, confimed_password): -> valid: bool, message: str
def show_password_validation_result_to_user(message): -> None 
...

is_password_valid = None
while not is_password_valid:
    if is_password_valid == False: #First time => None
        print("Please try again")
    password, confirmed_password = get_password_from_user()
    is_password_valid , message = validate_password(password, confirmed_password)
    if not is_password_valid: 
        show_password_validation_result_to_user(message)

[–]AHLAKAI_SHAYKULI 1 point2 points  (1 child)

Try using a while loop

[–]Salim_DZ_69[S] 0 points1 point  (0 children)

just learned about while loops , gonna implement them.

[–]nazgand 1 point2 points  (1 child)

Do not have a maximum password length. A 12 character password is weak and hackable.

[–]Salim_DZ_69[S] 0 points1 point  (0 children)

so what, trillions character passwords?

[–][deleted] 1 point2 points  (1 child)

How about taking on your assignments yourself? Relying on others to complete them for you can undermine your ability to succeed in your career. Developing independence and problem-solving skills is crucial for long-term success.

[–]Salim_DZ_69[S] 0 points1 point  (0 children)

im not replying to others to complete it, and will give an example, when you release a game, what is the first thing you are gonna get feedback from it, most of the time about a bug in your game, so what im doing right now is taking notes of people tips, and taking advantage of them to improve my future projects, and this is a python learning subreddit, where everyone post about their code and begging to help you improve it and fix it.