Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Crypto.Hash import MD5
- #import MySQLdb
- import getpass
- from config import Config
- f = file('pymmo.cfg')
- cfg = Config(f)
- sqlHost = cfg.sqlHost
- sqlUser = cfg.sqlUser
- sqlPass = cfg.sqlPass
- dataB = cfg.dataB
- def __md5Hash(string):
- md5 = MD5.new()
- md5.update(string)
- md5.update(md5.digest())
- return md5
- def md5Hash_hex(string):
- return __md5Hash(string).hexdigest()
- #conn = MySQLdb.connect(host = sqlHost,
- # user = sqlUser,
- # passwd = sqlPass,
- # db = dataB)
- #cursor = conn.cursor()
- def newUser():
- userName = raw_input("Enter user Name: ")
- passWord = getpass.getpass("Enter User Password: ")
- passWord = md5Hash_hex(passWord)
- newUserCommand = 'INSERT into authentication(userName,hash) VALUES(' + "'" + userName +"'" + ',' + "'" + passWord + "'" + ")"
- cursor.execute(newUserCommand)
- main()
- def deleteUser():
- print "Enter user name to delete: "
- userName = raw_input()
- deleteUserCommand = "DELETE from authentication WHERE userName = " + "'" + userName + "'"
- cursor.execute(deleteUserCommand)
- print "User deleted successfully."
- main()
- def changePass():
- print "Enter user name to change: "
- userName = raw_input()
- passWord = getpass.getpass("Enter new password: ")
- passWord = md5Hash_hex(passWord)
- changePassCommand = "UPDATE authentication set hash = " + "'" + passWord + "'" + " where userName = " + "'" + userName + "'"
- cursor.execute(changePassCommand)
- main()
- def main():
- userChoice = 0
- userSelection = """1: Add user 2: Delete user
- 3: Change user password 4: Quit"""
- print "User administration for PyMMO"
- print "What would you like to do?"
- print userSelection
- userChoice = raw_input("$: ")
- userChoice = int(userChoice)
- while (userChoice != 4):
- if (userChoice == 1):
- newUser()
- elif (userChoice == 2):
- deleteUser()
- elif (userChoice == 3):
- changePass()
- exit()
- if __name__ == '__main__':main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement