Advertisement
barbos01

onlinebanking1

Jun 21st, 2022
1,507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.55 KB | None | 0 0
  1. import hashlib
  2. import json
  3. import random
  4.  
  5.  
  6. class Utilizator:
  7.  
  8.     def __init__(self):
  9.         super().__init__()
  10.         self.email_utilizator = None
  11.  
  12.     def inregistrare(self):
  13.         email = input("Introduceti adresa de email:")
  14.         confirmare = False
  15.         while not confirmare:
  16.             parola = input("Introduceti parola:")
  17.             parola_confirmare = input("Confirmati parola:")
  18.             if parola != parola_confirmare:
  19.                 print("Cele doua parole nu coincid!")
  20.             else:
  21.                 confirmare = True
  22.         enc = parola.encode()
  23.         hash1 = hashlib.md5(enc).hexdigest()
  24.  
  25.         client = email + parola
  26.         client_enc = client.encode()
  27.         client_hash = hashlib.md5(client_enc).hexdigest()
  28.         json_object = {str(client_hash): [{"email": email, "password": hash1}]}
  29.  
  30.         inputfile = open('credentials.json')
  31.         json_object_loaded = json.load(inputfile)
  32.         if client_hash in json_object_loaded:
  33.             print("Acest cont exista!")
  34.             return
  35.  
  36.         dict_final = {**json_object_loaded, **json_object}
  37.         with open("credentials.json", "w") as outfile:
  38.             outfile.write(json.dumps(dict_final))
  39.         outfile.close()
  40.         print("Te-ai inregistrat cu succes!")
  41.  
  42.     def conectare(self):
  43.         email = input("Introduceti adresa de email:")
  44.         parola = input("Introduceti parola:")
  45.  
  46.         client = email + parola
  47.         client_enc = client.encode()
  48.         client_hash = hashlib.md5(client_enc).hexdigest()
  49.  
  50.         inputfile = open('credentials.json')
  51.         json_object_loaded = json.load(inputfile)
  52.         if client_hash in json_object_loaded:
  53.             print("Te-ai conectat cu succes!")
  54.             self.email_utilizator = email
  55.             return True
  56.         else:
  57.             print("Datele sunt incorecte!")
  58.  
  59.  
  60. def cardValidare(number):
  61.     lenght = len(number)
  62.     if lenght > 16 or lenght < 16:
  63.         return False
  64.     digits = [int(x) for x in str(number)]
  65.  
  66.     for el in range(1, lenght, 2):
  67.         digits[el] *= 2
  68.         if digits[el] >= 9:
  69.             digits[el] = int(digits[el] % 10 + (digits[el] / 10) % 10)
  70.     digits_sum = 0
  71.     for i in range(lenght - 1):
  72.         digits_sum += digits[i]
  73.  
  74.  
  75.     prod_check = digits_sum * 9
  76.     if prod_check % 10 == digits[lenght - 1]:
  77.         return True
  78.     return False
  79.  
  80. def furnizor(nume):
  81.     while 1:
  82.         print(f"\nAti ales furnizorul {nume}")
  83.         print("Introduceti urmatoarele date")
  84.         cod_client = int(input("Introduceti codul de client:"))
  85.         numar_loc_consum = int(input("Introduceti numarul locului de consum: "))
  86.         print("Total de plata:", random.randint(30, 150))
  87.         card = input("Introduceti numarul cardului")
  88.         if not cardValidare(str(card)):
  89.             print("Numarul cardului este incorect!\n")
  90.         data = input("Introduceti data de expirare: ex 10/23")
  91.         ccv = 0
  92.         while ccv < 100 or ccv > 1000:
  93.             ccv = int(input("Introduceti ccv-ul de pe spatele cardului:"))
  94.         print("Plata a fost procesata cu succes!")
  95.         return True
  96.  
  97.  
  98. if __name__ == '__main__':
  99.     aplicatie = Utilizator()
  100.     while 1:
  101.         print("\n\n********** Online Banking **********")
  102.         print("1.Inregistrare")
  103.         print("2.Conectare")
  104.         print("3.Exit")
  105.         try:
  106.             ch = int(input("Alegerea dumneavoastra:"))
  107.         except:
  108.             print("Introduceti un numar!")
  109.             continue
  110.         if ch == 1:
  111.             aplicatie.inregistrare()
  112.         elif ch == 2:
  113.             conectare = aplicatie.conectare()
  114.             if conectare:
  115.                 break
  116.         elif ch == 3:
  117.             break
  118.         else:
  119.             print("Alegere gresita!")
  120.     nr_facturi = 0
  121.     while conectare:
  122.         print("\n\n********** Alege furnizorii **********")
  123.         print((f"******** Utilizator {aplicatie.email_utilizator} ********"))
  124.         print("1.Enel")
  125.         print("2.Electrica")
  126.         print("3.Exit")
  127.         try:
  128.             ch = int(input("Alegerea dumneavoastra:"))
  129.         except:
  130.             print("Introduceti un numar!")
  131.             continue
  132.  
  133.         if ch == 1:
  134.             plata = furnizor("Enel")
  135.             if plata:
  136.                 nr_facturi += 1
  137.         elif ch == 2:
  138.             plata = furnizor("Electrica")
  139.             if plata:
  140.                 nr_facturi += 1
  141.         elif ch == 3:
  142.             break
  143.         else:
  144.             print("Alegere gresita!")
  145.     if nr_facturi:
  146.         print(f"Ati  platit {nr_facturi} factura/i!")
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement