Skip to content

Instantly share code, notes, and snippets.

@hackerdem
Created May 14, 2016 07:45
Show Gist options
  • Save hackerdem/da9d1009e769d6d47f46769a4ca5023c to your computer and use it in GitHub Desktop.
Save hackerdem/da9d1009e769d6d47f46769a4ca5023c to your computer and use it in GitHub Desktop.
python simple encryption and database connection example
from passlib.hash import pbkdf2_sha256
import getpass
import mysql.connector
def enc_pass(pwd):
hash=pbkdf2_sha256.encrypt(pwd,rounds=200,salt_size=16)
return hash
def con_database(pwd):
cnx=mysql.connector.connect(user='*****',password='*****',host='*******',database='******')
cursor=cnx.cursor()
try:
query=("INSERT INTO usr VALUES(%s,%s);")
data=(us,pwd)
cursor.execute(query,data)
cnx.commit()
print("user recorded")
except Exception as e:
print(e)
def user_data():
global us
print("Please enter username:")
us=input(">>")
print("Please enter password:")
pwd=getpass.getpass(">>")
return pwd
if __name__=="__main__":
con_database(enc_pass(user_data()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment