mfx28

Programacao2

Jun 5th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.28 KB | None | 0 0
  1. from sys import exit
  2. import re
  3. import os.path
  4. import zlib
  5.  
  6. #Pelo menos 2 minusculas
  7. def check_lower(input):
  8.     lowers = 0
  9.     lower_list = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split()
  10.     for char in input:
  11.         if char in lower_list:
  12.             lowers += 1
  13.     if lowers > 1:
  14.         return True
  15.     else:
  16.         return False
  17.  
  18. def check_special(input):
  19.     specials = 0
  20.     special_list = "a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 0 ' ' ! # - * + & % @ _".split() #NAO PODE VER EM CASA
  21.     for char in input:
  22.         if char in special_list:
  23.             specials += 1
  24.     if specials > 0:
  25.         return True
  26.     else:
  27.         return False
  28.  
  29. def check_len(input):
  30.     if len(input) >= 8:
  31.         return True
  32.     else:
  33.         return False
  34.  
  35. def comecar_letra(input):
  36.     lista_char = "a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split()
  37.     for char in input:
  38.         if char[0] in lista_char:
  39.             return True
  40.         else:
  41.             return False
  42.  
  43. def duasminusculasseguidas(input):
  44.     checker = re.compile(r'([a-z][a-z])')
  45.     if re.search(checker, input):
  46.         return True
  47.     else:
  48.         return False
  49.  
  50. def registo():
  51.     file = open("Contas.txt","a")
  52.     file.write(numeroaluno)
  53.     file.write(" ")
  54.     file.write(password)
  55.     file.write("\n")
  56.     file.close()
  57.  
  58. def verificar():
  59.     try:
  60.         for line in open("Contas.txt","r").readlines(): # Read the lines
  61.             login_info = line.split()
  62.             if numeroaluno == login_info[0]:
  63.                 print("Ja existe esse numero de aluno")
  64.             else:
  65.                 registo()
  66.     except:
  67.         file = open("Contas.txt","a")
  68.         file.close()
  69.         registo()
  70.        
  71. def validate_password(input):
  72.     check_dict = {
  73.         'lower': check_lower(input),
  74.         'minus': duasminusculasseguidas(input),
  75.         'special': check_special(input),
  76.         'len' : check_len(input),
  77.         'let' : comecar_letra(input)
  78.     }
  79.     if check_lower(input) & check_special(input) & check_len(input) & comecar_letra(input) & duasminusculasseguidas(input):
  80.         return True
  81.     else:
  82.         print ("Password Invalida! Verifica os problemas seguintes !")
  83.         print
  84.         if check_dict['lower'] == False:
  85.             print ("Password tem de ter pelo menos 2 caracteres minusculos.")
  86.         if check_dict['special'] == False:
  87.             print ("Password needs at least one special character.")
  88.         if check_dict['len'] == False:
  89.             print ("Password tem de ter pelo menos 8 caracteres.")
  90.         if check_dict['let'] == False:
  91.             print ("Password tem de comecar por 1 letra.")
  92.         if check_dict['minus'] == False:
  93.             print ("Password precisa de ter 2 letras minusculas consecutivas")  
  94.         print                  
  95.  
  96. numeroaluno = input("Introduza o numero do aluno: ")
  97. while True:
  98.     password = input("Introduza uma password: ")
  99.     print
  100.     if validate_password(password):
  101.         print ("Requerimentos da password foram compridos.")
  102.         print
  103.         # print (hex(zlib.crc32(b'pedro') & 0xffffffff))
  104.         verificar()
  105.         print
  106.         exit(0)
Add Comment
Please, Sign In to add comment