Python Password Generator
This commit is contained in:
24
README.md
24
README.md
@@ -1,2 +1,24 @@
|
||||
# Random_password_generator
|
||||
# Python Password Generator
|
||||
|
||||
ЭТОТ ПРОСТОЙ ПРОЕКТ БЫЛ СДЕЛАН С ИСПОЛЬЗОВАНИЕМ БИБЛИОТЕЧНЫХ ФУНКЦИЙ PYTHON, ТАКИХ, как string & random значения.
|
||||
|
||||
> string.ascii_letters
|
||||
Объединение констант ascii_lowercase и ascii_uppercase, описанное ниже. Это значение не зависит от локали.
|
||||
|
||||
> string.ascii_lowercase
|
||||
Строчные буквы abcdefghijklmnopqrstuvwxyz. Это значение не зависит от локали и не изменится.
|
||||
|
||||
> string.ascii_uppercase
|
||||
Прописные буквы ABCDEFGHIJKLMNOPQRSTUVWXYZ. Это значение не зависит от локали и не изменится.
|
||||
|
||||
> string.digits
|
||||
The string 0123456789.
|
||||
|
||||
> string.hexdigits
|
||||
The string 0123456789abcdefABCDEF.
|
||||
|
||||
> string.octdigits
|
||||
The string 01234567.
|
||||
|
||||
> string.punctuation
|
||||
Строка символов ASCII, которые считаются знаками пунктуации в локали C: !"#$%&'()*+,-./:;<=>?@[\]
|
||||
|
||||
10
python-password-generator.py
Normal file
10
python-password-generator.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
total = string.ascii_letters + string.digits + string.punctuation
|
||||
|
||||
length = 16
|
||||
|
||||
password = "".join(random.sample(total, length))
|
||||
|
||||
print(password)
|
||||
43
random_password_gen.py
Normal file
43
random_password_gen.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import random
|
||||
import math
|
||||
|
||||
alpha = "abcdefghijklmnopqrstuvwxyz"
|
||||
num = "0123456789"
|
||||
special = "@#$%&*"
|
||||
|
||||
# pass_len=random.randint(8,13) #without User INput
|
||||
pass_len = int(input("Enter Password Length"))
|
||||
|
||||
# length of password by 50-30-20 formula
|
||||
alpha_len = pass_len//2
|
||||
num_len = math.ceil(pass_len*30/100)
|
||||
special_len = pass_len-(alpha_len+num_len)
|
||||
|
||||
|
||||
password = []
|
||||
|
||||
|
||||
def generate_pass(length, array, is_alpha=False):
|
||||
for i in range(length):
|
||||
index = random.randint(0, len(array) - 1)
|
||||
character = array[index]
|
||||
if is_alpha:
|
||||
case = random.randint(0, 1)
|
||||
if case == 1:
|
||||
character = character.upper()
|
||||
password.append(character)
|
||||
|
||||
|
||||
# alpha password
|
||||
generate_pass(alpha_len, alpha, True)
|
||||
# numeric password
|
||||
generate_pass(num_len, num)
|
||||
# special Character password
|
||||
generate_pass(special_len, special)
|
||||
# suffle the generated password list
|
||||
random.shuffle(password)
|
||||
# convert List To string
|
||||
gen_password = ""
|
||||
for i in password:
|
||||
gen_password = gen_password + str(i)
|
||||
print(gen_password)
|
||||
Reference in New Issue
Block a user