Skip to content

Instantly share code, notes, and snippets.

@glassus

glassus/code5.py Secret

Created December 3, 2020 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glassus/446fbe11420536bf79bb30e1098dc1b2 to your computer and use it in GitHub Desktop.
Save glassus/446fbe11420536bf79bb30e1098dc1b2 to your computer and use it in GitHub Desktop.
import sqlite3
import hashlib
connexion = sqlite3.connect('secretdata.db')
c = connexion.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS secret(
login TEXT,
password TEXT,
secret_texte TEXT);
""")
connexion.commit()
def menu():
print('-------------')
print('1. login \n2. register\n3. quit')
print('-------------')
rep = int(input("choix ?"))
return rep
def register():
login_identique = True
while login_identique == True :
login = input("choississez votre login : ")
tlogin = (login,)
c.execute("""
SELECT COUNT(*) FROM secret WHERE login = ?
""",tlogin)
if c.fetchone()[0] > 0 :
print("login déjà utilisé")
else :
login_identique = False
pwd = input("choississez votre mot de passe : ")
pwd_hash = hashlib.md5(pwd.encode()).hexdigest()
phrase_secrete = input("tapez la phrase secrète que vous voulez conserver : ")
data = (login, pwd_hash, phrase_secrete)
c.execute('''
INSERT INTO secret VALUES (?,?,?)
''', data)
connexion.commit()
def login():
login_existant = False
while login_existant == False :
login = input("login : ")
tlogin = (login,)
c.execute("""
SELECT COUNT(*) FROM secret WHERE login = ?
""",tlogin)
if c.fetchone()[0] == 0 :
print("login inconnu")
else :
login_existant = True
pwd = input("mot de passe : ")
pwd_hash = hashlib.md5(pwd.encode()).hexdigest()
c.execute("""
SELECT password, secret_texte FROM secret WHERE login = ?
""",tlogin)
result = c.fetchone()
pwd_recorded = result[0]
if pwd_hash == pwd_recorded :
print("phrase secrète : ", result[1])
else :
print("wrong password")
while True :
r = menu()
if r == 3 :
break
if r == 2 :
register()
if r == 1 :
login()
connexion.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment