Guest User

Untitled

a guest
Feb 18th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import getpass
  4. import hashlib
  5.  
  6. usernamedb=['admin']
  7. passworddb=['f248aa0a9dc1aaeb1e7b0111585c06b909943f9626eaddd6d5305a0ce26e8c509327686b799de23898e28ae1b0d94a23e18878499b95c7ddb7d70a0b013d5931']
  8. loginstatus=False
  9. salt='dae9Eu2Ughiwu9maeNeichah1Pho6aaT'
  10.  
  11. def create_user():
  12. running=True
  13.  
  14. while running:
  15. newusername=raw_input('Please enter a new username : ')
  16. newuserspassword=getpass.getpass('Please enter a password : ')
  17. newhashedpassword=hashlib.sha512()
  18. newuserspassword2=getpass.getpass('Please confirm the password : ')
  19. if newuserspassword==newuserspassword2:
  20. newhashedpassword.update(newuserspassword+salt)
  21. hashedtoaddtodb=newhashedpassword.hexdigest()
  22. usernamedb.append(newusername)
  23. passworddb.append(hashedtoaddtodb)
  24. print 'The new user has been created'
  25. makenewuser=raw_input('Would you like to create another user? (y/n) : ')
  26. if makenewuser=='n':
  27. break
  28. if makenewuser=='y':
  29. continue
  30. else:
  31. print 'Invalid input, taking you to login screen'
  32. break
  33. else:
  34. print 'Error, passwords do not match'
  35. continue
  36.  
  37.  
  38. def login():
  39. print 'Welcome to the system'
  40. running=True
  41. attempts=0
  42. remaining=3
  43. while running:
  44. username=raw_input('Please enter your username : ')
  45. password=getpass.getpass('Please enter your password : ')
  46. hashedinputpassword=hashlib.sha512()
  47. hashedinputpassword.update(password+salt)
  48. inputpassworddigest=hashedinputpassword.hexdigest()
  49. ID=usernamedb.index(username)
  50. if passworddb[ID]==inputpassworddigest:
  51. global loginstatus
  52. loginstatus=True
  53. print 'Welcome', username
  54. break
  55. if passworddb[ID]!=inputpassworddigest and remaining != 0:
  56. print 'Invalid password, please try again'
  57. attempts=attempts+1
  58. remaining=2-attempts
  59. print remaining+1, 'attempts remaining'
  60. continue
  61. if passworddb[ID]!=inputpassworddigest and remaining==0:
  62. print 'You have failed to login too many times'
  63. break
  64.  
  65. select=raw_input('Would you like to create a new user before continuing? (y/n)')
  66.  
  67. if select=='y':
  68. create_user()
  69. if select=='n':
  70. login()
  71. else:
  72. print 'Invalid input'
Add Comment
Please, Sign In to add comment