Advertisement
Guest User

Untitled

a guest
May 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. from Crypto.Hash import MD5
  2. #import MySQLdb
  3. import getpass
  4. from config import Config
  5.  
  6. f = file('pymmo.cfg')
  7. cfg = Config(f)
  8. sqlHost = cfg.sqlHost
  9. sqlUser = cfg.sqlUser
  10. sqlPass = cfg.sqlPass
  11. dataB = cfg.dataB
  12.  
  13. def __md5Hash(string):
  14.     md5 = MD5.new()
  15.     md5.update(string)
  16.     md5.update(md5.digest())
  17.     return md5
  18.  
  19. def md5Hash_hex(string):
  20.     return __md5Hash(string).hexdigest()
  21.  
  22. #conn = MySQLdb.connect(host = sqlHost,
  23. #                       user = sqlUser,
  24. #                      passwd = sqlPass,
  25. #                      db = dataB)
  26. #cursor = conn.cursor()
  27. def newUser():
  28.     userName = raw_input("Enter user Name: ")
  29.  
  30.     passWord = getpass.getpass("Enter User Password: ")
  31.  
  32.     passWord = md5Hash_hex(passWord)
  33.  
  34.     newUserCommand = 'INSERT into authentication(userName,hash) VALUES(' + "'" + userName +"'" + ',' + "'" + passWord + "'" + ")"
  35.     cursor.execute(newUserCommand)
  36.     main()
  37.  
  38. def deleteUser():
  39.     print "Enter user name to delete: "
  40.     userName = raw_input()
  41.    
  42.     deleteUserCommand = "DELETE from authentication WHERE userName = " + "'" + userName + "'"
  43.     cursor.execute(deleteUserCommand)
  44.     print "User deleted successfully."
  45.     main()
  46.  
  47. def changePass():
  48.     print "Enter user name to change: "
  49.     userName = raw_input()
  50.    
  51.     passWord = getpass.getpass("Enter new password: ")
  52.     passWord = md5Hash_hex(passWord)
  53.    
  54.     changePassCommand = "UPDATE authentication set hash = " + "'" + passWord + "'" + " where userName = " + "'" + userName + "'"
  55.     cursor.execute(changePassCommand)
  56.     main()
  57.    
  58. def main():
  59.     userChoice = 0
  60.     userSelection = """1: Add user                 2: Delete user
  61. 3: Change user password     4: Quit"""
  62.  
  63.     print "User administration for PyMMO"
  64.     print "What would you like to do?"
  65.     print userSelection
  66.     userChoice = raw_input("$: ")
  67.     userChoice = int(userChoice)
  68.     while (userChoice != 4):
  69.         if (userChoice == 1):
  70.             newUser()
  71.         elif (userChoice == 2):
  72.             deleteUser()
  73.         elif (userChoice == 3):
  74.             changePass()
  75.     exit()
  76. if __name__ == '__main__':main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement