Advertisement
Guest User

Dead Simple User Login Database in Python Under 50 Lines

a guest
Nov 3rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. import datetime
  2. import os
  3. def main():
  4.   my_dict = {}
  5.   count = 0
  6.   time = datetime.datetime.now().strftime("%a, %d %B %Y %H:%M:%S")
  7.   print(time)
  8.   userCount = float(input("How many members are being logged?: "))
  9.   while count < userCount:
  10.     member = input("Enter desired member login: ")
  11.     password = input("Enter desired password [DIGITS ONLY!]: ")
  12.     while not password.isdigit():
  13.       print('Invalid Password!')
  14.       password = input("Enter desired password [DIGITS ONLY!]: ")
  15.     userInfo = member+','+password+'\n'
  16.     myfile = open('myfile.txt','a')
  17.     myfile.write(userInfo)
  18.     count += 1
  19.     myfile.close()
  20.   myfile = open('myfile.txt','r')
  21.   for line in myfile.readlines():
  22.     line = line.split(',')
  23.     key = line[0].strip()
  24.     value = line[1].strip()
  25.     my_dict[key] = value
  26.   logger(my_dict,time,key,value)
  27. def logger(my_dict,time,key,value):
  28.   userSearch = input("Search for a user: ")
  29.   if userSearch in my_dict.keys():
  30.     print("User Found!")
  31.     login = input("Do you want to login into the given user? [y/n]: ")
  32.     if login == 'y':
  33.       password = input('Enter Password: ')
  34.       if password == my_dict.get(userSearch,value):
  35.         print('\n')
  36.         print(time)
  37.         print("Welcome!")
  38.         input("Press any key to quit example.") #to keep open until any key pressed
  39.       else:
  40.         print("Incorrect Password!")
  41.     else:
  42.       logger()
  43.   else:
  44.     print("User Not Found!")
  45. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement