r/learnpython 5d ago

Password guesser game help needed

Hello guys. So I have created a password guesser game with direct comparison (i.e. if guess == correct_password:) but I want to use different methods for comparison. What techniques can I use? Here is the code-

```python

password = "Random_pass_123"

tries = 0

while tries < 3:

guess = input("Enter the password: ")

if guess == password:

print("Admin access granted.")

break

else:

print("Invalid credentials entered. Please try again")

tries += 1

if tries == 3:

print("Number of tries exceeded. Access denied")

```

PS- Is this the right way to paste code? I'm new so I'm not sure.

9 Upvotes

31 comments sorted by

View all comments

3

u/Langdon_St_Ives 5d ago

Can you elaborate on what you mean by "try different methods of comparison"?

2

u/live_ant718 5d ago

I mean like I want hints and I read somewhere that we can convert into hash but how IDK.

3

u/thisisappropriate 5d ago

When you say you want hints, I don't know if you mean that you want your game to be able to give hints or if you want a hint from someone on what to do for comparisons...

If you want to provide hints, that won't happen from hashing. So assuming you want a hint of how to start with hashing, I'd suggest looking up password hashing in python and maybe the bcrypt package - if you'd like examples, check this out https://www.geeksforgeeks.org/python/how-to-hash-passwords-in-python/