#๐Ÿ”’ Password Generation Python

21 messages ยท Page 1 of 1 (latest)

lime solar
#

I want to create a Password generation project in python. How can I do it. I have tried to code it but didn't work. Help me.

tall reefBOT
#

@lime solar

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.

heady lodge
woven niche
#

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?

tall reefBOT
#

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.

heady lodge
woven niche
#

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)

river oxide
#

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

woven niche
#

besides LOC won't differ much between random and secrets

oak pulsar
# lime solar I want to create a Password generation project in python. How can I do it. I hav...

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)
tall reefBOT
#

@oak pulsar :white_check_mark: Your 3.12 eval job has completed with return code 0.

7FhnXMM0f1
tall reefBOT
#
Python help channel closed

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.