In [19]:
import pymongo
from pymongo import MongoClient
import getpass
import base64
In [36]:
client = MongoClient('localhost:27017')
db = client.arXivDB
db.users.count()
Out[36]:
In [49]:
while True:
user = {}
user['username'] = input('choose username: ').lower()
user['pin'] = base64.b64encode(bytes(str(getpass.getpass('choose pin: ')), encoding="UTF-8"))
if db.users.find({'username': user['username']}).count():
print('the username already exists, try a new one')
else:
db.users.insert_one(user)
username = None
pin = None
break
print('the total number of users is: {}'.format(db.users.count()))
In [44]:
list(db.users.find({}))
Out[44]:
In [ ]: