Skip to content

Instantly share code, notes, and snippets.

@lecuseasar
Created March 17, 2021 13:25
Show Gist options
  • Save lecuseasar/d8e3eb91acea94bb8ba7e12760f16e30 to your computer and use it in GitHub Desktop.
Save lecuseasar/d8e3eb91acea94bb8ba7e12760f16e30 to your computer and use it in GitHub Desktop.
1. En az bir büyük harf, en az bir küçük harf, en az 8 karakter alfanumerik bir şifre oluşturma politikasına göre rastgele şifre üreten bir program yazınız. 2. Rastgele şifreler belirleyerek yada üreterek 1.maddede ki kriterlere uymayan şifreleri belirleyiniz
import string
import random
# * https://docs.python.org/3/library/string.html
letters_lowercase = string.ascii_lowercase
letters_uppercase = string.ascii_uppercase
numbers = string.digits
length = 8
def check_password(arr):
check1 = False
check2 = False
check3 = False
for i in arr:
if letters_lowercase.find(i) > -1:
check1 = True
if letters_uppercase.find(i) > -1:
check2 = True
if numbers.find(i) > -1:
check3 = True
if check1 == True and check2 == True and check3 == True:
print('Correct password') # ! return True
else:
print('Wrong password') # ! return False
def random_password():
# * https://realpython.com/python-string-formatting/
arr = list(f'{letters_lowercase}{letters_uppercase}{numbers}')
random.shuffle(arr)
# * https://www.w3schools.com/python/ref_random_choices.asp
random_char_arr = random.choices(arr, k=length) # ! [ '', '', '', '']
# * https://www.geeksforgeeks.org/python-string-find/
check_password(random_char_arr)
random_password = ''.join(random_char_arr)
return random_password
print(f'{random_password()}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment