Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. def Register():
  2. print('Register your login: ', end='')
  3. login = input()
  4. print('Register your password ', end='')
  5. password = input()
  6. checkPassword(password)
  7. Rights()
  8. fileNames = open('usernames.txt', 'a')
  9. fileNames.write('\n' + login)
  10. filePasswords = open('passwords.txt', 'a')
  11. filePasswords.write('\n' + password)
  12. fileRights = open('privileges.txt', 'a')
  13. fileRights.write('\n' + Rights())
  14.  
  15.  
  16.  
  17.  
  18. def checkPassword(password):
  19. if len(password) == 4:
  20. return True
  21. else:
  22. print('Password length must be 4 symbols!')
  23. newPassword = input()
  24. checkPassword(newPassword)
  25.  
  26.  
  27. def Rights():
  28. print('Choose your rights: D or/and C ', end='')
  29. rights = input().strip()
  30. if rights == 'C':
  31. return 'C'
  32. elif rights == 'D':
  33. return 'D'
  34. elif rights == 'C and D' or 'D and C' or 'C, D' or 'D, C':
  35. return 'C D'
  36. else:
  37. print('You are trying to put wrong rights')
  38. Rights()
  39.  
  40. import getpass
  41. import numpy as np
  42. import registration
  43.  
  44. class User:
  45. def __init__(self, name, password, privilege):
  46. self.name = name
  47. self.password = password
  48. self.privilege = privilege
  49.  
  50. def Authentificate():
  51. while True:
  52. print('Login: ', end='')
  53. name = input()
  54. password = getpass.getpass('Enter password:')
  55. usernames = open('usernames.txt', 'r')
  56. passwords = open('passwords.txt', 'r')
  57. privileges = open('privileges.txt', 'r')
  58.  
  59. dataname = np.array(usernames.read().split('\n'))
  60. datapass = np.array(passwords.read().split('\n'))
  61. dataprivilege = np.array(privileges.read().split('\n'))
  62. numbUsers = int(dataname.size)
  63.  
  64. loginCheck = False
  65. for i in range(numbUsers):
  66. if dataname[i] == name:
  67. loginCheck = True
  68. if datapass[i] == password:
  69. print('You have rights of category: ', dataprivilege[i])
  70. return User(name, password, dataprivilege[i])
  71. break
  72. else:
  73. print('Wrong password')
  74. if loginCheck == False:
  75. print('Wrong login')
  76.  
  77. def Reg():
  78. answer = input()
  79. if answer == 'y':
  80. registration.Register()
  81. elif answer == 'n':
  82. Authentificate()
  83. else:
  84. print('Enter y or n')
  85. Reg()
  86.  
  87. print('Do you want to register new user? y/n ', end='')
  88. Reg()
  89. Authentificate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement