#๐ Password Generation Python
21 messages ยท Page 1 of 1 (latest)
@lime solar
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.
Make a list of the characters, and use a for loop and random.choice
that is not how you generate a (secure) password
that technicallly works
but, you'd ideally use secrets
!d secrets look into this for generating passwords, as for "didn't work" what exactly didn't work?
New in version 3.6.
Source code: Lib/secrets.py
The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.
In particular, secrets should be used in preference to the default pseudo-random number generator in the random module, which is designed for modelling and simulation, not security or cryptography.
it for beginners, the simplest way
secrets is not convuluted in any manner
you could even do secrets.choice as a drop in replacement (you shouldn't though, there's simpler and better ways)
i think he wants to program it himself, for the fun of it and to practise and not just use a ready-made module, because then there is nothing left to program
there's still a lot you can do to improve functionality rather than just chuck out a password, like a password manager cli/tui/gui
besides LOC won't differ much between random and secrets
Let us say you wanted to generate a ten character password with at least one upper case letter, at least one lower case letter and at least three digits, then you could do it like this. This is just an example and you could adapt this easily to suit your particular requirements.
import string, secrets
alphabet = string.ascii_letters + string.digits
while True:
password = ''.join(secrets.choice(alphabet) for i in range(10))
if ( any(char.islower() for char in password) and
any(char.isupper() for char in password) and
sum(char.isdigit() for char in password) >= 3):
break
print(password)
!e
import string, secrets
alphabet = string.ascii_letters + string.digits
while True:
password = ''.join(secrets.choice(alphabet) for i in range(10))
if ( any(char.islower() for char in password) and
any(char.isupper() for char in password) and
sum(char.isdigit() for char in password) >= 3):
break
print(password)
@oak pulsar :white_check_mark: Your 3.12 eval job has completed with return code 0.
7FhnXMM0f1
Thanks
I need that
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.