Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- import json
- import random
- class Utilizator:
- def __init__(self):
- super().__init__()
- self.email_utilizator = None
- def inregistrare(self):
- email = input("Introduceti adresa de email:")
- confirmare = False
- while not confirmare:
- parola = input("Introduceti parola:")
- parola_confirmare = input("Confirmati parola:")
- if parola != parola_confirmare:
- print("Cele doua parole nu coincid!")
- else:
- confirmare = True
- enc = parola.encode()
- hash1 = hashlib.md5(enc).hexdigest()
- client = email + parola
- client_enc = client.encode()
- client_hash = hashlib.md5(client_enc).hexdigest()
- json_object = {str(client_hash): [{"email": email, "password": hash1}]}
- inputfile = open('credentials.json')
- json_object_loaded = json.load(inputfile)
- if client_hash in json_object_loaded:
- print("Acest cont exista!")
- return
- dict_final = {**json_object_loaded, **json_object}
- with open("credentials.json", "w") as outfile:
- outfile.write(json.dumps(dict_final))
- outfile.close()
- print("Te-ai inregistrat cu succes!")
- def conectare(self):
- email = input("Introduceti adresa de email:")
- parola = input("Introduceti parola:")
- client = email + parola
- client_enc = client.encode()
- client_hash = hashlib.md5(client_enc).hexdigest()
- inputfile = open('credentials.json')
- json_object_loaded = json.load(inputfile)
- if client_hash in json_object_loaded:
- print("Te-ai conectat cu succes!")
- self.email_utilizator = email
- return True
- else:
- print("Datele sunt incorecte!")
- def cardValidare(number):
- lenght = len(number)
- if lenght > 16 or lenght < 16:
- return False
- digits = [int(x) for x in str(number)]
- for el in range(1, lenght, 2):
- digits[el] *= 2
- if digits[el] >= 9:
- digits[el] = int(digits[el] % 10 + (digits[el] / 10) % 10)
- digits_sum = 0
- for i in range(lenght - 1):
- digits_sum += digits[i]
- prod_check = digits_sum * 9
- if prod_check % 10 == digits[lenght - 1]:
- return True
- return False
- def furnizor(nume):
- while 1:
- print(f"\nAti ales furnizorul {nume}")
- print("Introduceti urmatoarele date")
- cod_client = int(input("Introduceti codul de client:"))
- numar_loc_consum = int(input("Introduceti numarul locului de consum: "))
- print("Total de plata:", random.randint(30, 150))
- card = input("Introduceti numarul cardului")
- if not cardValidare(str(card)):
- print("Numarul cardului este incorect!\n")
- data = input("Introduceti data de expirare: ex 10/23")
- ccv = 0
- while ccv < 100 or ccv > 1000:
- ccv = int(input("Introduceti ccv-ul de pe spatele cardului:"))
- print("Plata a fost procesata cu succes!")
- return True
- if __name__ == '__main__':
- aplicatie = Utilizator()
- while 1:
- print("\n\n********** Online Banking **********")
- print("1.Inregistrare")
- print("2.Conectare")
- print("3.Exit")
- try:
- ch = int(input("Alegerea dumneavoastra:"))
- except:
- print("Introduceti un numar!")
- continue
- if ch == 1:
- aplicatie.inregistrare()
- elif ch == 2:
- conectare = aplicatie.conectare()
- if conectare:
- break
- elif ch == 3:
- break
- else:
- print("Alegere gresita!")
- nr_facturi = 0
- while conectare:
- print("\n\n********** Alege furnizorii **********")
- print((f"******** Utilizator {aplicatie.email_utilizator} ********"))
- print("1.Enel")
- print("2.Electrica")
- print("3.Exit")
- try:
- ch = int(input("Alegerea dumneavoastra:"))
- except:
- print("Introduceti un numar!")
- continue
- if ch == 1:
- plata = furnizor("Enel")
- if plata:
- nr_facturi += 1
- elif ch == 2:
- plata = furnizor("Electrica")
- if plata:
- nr_facturi += 1
- elif ch == 3:
- break
- else:
- print("Alegere gresita!")
- if nr_facturi:
- print(f"Ati platit {nr_facturi} factura/i!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement