def change_password(uid, password): """ Changes uid's password. Checking of the old password _MUST_ be done before this. """ password = generate_password(password) return r.hset(K.USER.format(uid), 'password', password)
def create_account(username, email, password): """Creates a new user account. :param username: The new users user name :type username: str :param email: The new users e-mail address :type email: str :param password: The new users password un-hashed :type password: str :returns: The UID of the new user :rtype: str or None """ username = username.lower() email = email.lower() try: if check_username(username) and check_username_pattern(username) and \ check_email(email) and check_email_pattern(email): # Get a new UUID for the user uid = get_uuid() user = { '_id': uid, 'username': username.lower(), 'email': email.lower(), 'password': generate_password(password, method='pbkdf2:sha256:2000', salt_length=20), 'created': timestamp(), 'last_login': -1, 'active': False, 'banned': False, 'op': False, 'muted': False, 'about': "", 'score': 0, 'alerts_last_checked': -1, # Set the TTL for a newly created user, this has to be Datetime # object for MongoDB to recognise it. This is removed on # activation. 'ttl': datetime.utcnow() } # Set all the tips for new users for tip_name in k.VALID_TIP_NAMES: user['tip_{}'.format(tip_name)] = True # Insert the new user in to Mongo. If this fails a None will be # returned result = m.db.users.insert(user) return uid if result else None except DuplicateKeyError: # pragma: no cover # Oh no something went wrong. Pass over it. A None will be returned. pass return None
def create_account(username, email, password): """Creates a new user account. :param username: The new users user name :type username: str :param email: The new users e-mail address :type email: str :param password: The new users password un-hashed :type password: str :returns: The UID of the new user :rtype: str or None """ username = username.lower() email = email.lower() try: if ( check_username(username) and check_username_pattern(username) and check_email(email) and check_email_pattern(email) ): # Get a new UUID for the user uid = get_uuid() user = { "_id": uid, "username": username.lower(), "email": email.lower(), "password": generate_password(password, method="pbkdf2:sha256:2000", salt_length=20), "created": timestamp(), "last_login": -1, "active": False, "banned": False, "op": False, "muted": False, "about": "", "score": 0, "alerts_last_checked": -1, # Set the TTL for a newly created user, this has to be Datetime # object for MongoDB to recognise it. This is removed on # activation. "ttl": datetime.utcnow(), } # Insert the new user in to Mongo. If this fails a None will be # returned result = m.db.users.insert(user) return uid if result else None except DuplicateKeyError: # pragma: no cover # Oh no something went wrong. Pass over it. A None will be returned. pass return None
def change_password(user_id, password): """Changes user with ``user_id``s password. Checking of the old password MUST be done before you run this! This is a an unsafe function. You will also need to apply sanity (length etc.) checks outside this function. """ # Create the password hash from the plain-text password password = generate_password(password, method="pbkdf2:sha256:2000", salt_length=20) return m.db.users.update({"_id": user_id}, {"$set": {"password": password}})
def change_password(user_id, password): """Changes user with ``user_id``s password. Checking of the old password MUST be done before you run this! This is a an unsafe function. You will also need to apply sanity (length etc.) checks outside this function. """ # Create the password hash from the plain-text password password = generate_password(password, method='pbkdf2:sha256:2000', salt_length=20) return m.db.users.update({'_id': user_id}, {'$set': { 'password': password }})
def create_user(username, email, password): """Creates a user account """ username = username.lower() email = email.lower() if check_username(username) and check_email(email) and \ check_username_pattern(username) and check_email_pattern(email): # Create the user lookup keys. This LUA script ensures # that the name can not be taken at the same time causing a race # condition. This is also passed a UUID and will only return it if # successful uid = L.create_user(keys=[K.UID_USERNAME.format(username), K.UID_EMAIL.format(email)], args=[get_uuid()]) # Create user dictionary ready for HMSET only if uid is not None # This will only be None in the event of a race condition which we cant # really test for. if uid is not None: # pragma: no branch user = { 'uid': uid, 'username': username, 'email': email, 'password': generate_password(password), 'created': timestamp(), 'last_login': -1, 'active': 0, 'banned': 0, 'op': 0, 'muted': 0, 'about': "", 'score': 0, 'alerts_last_checked': 0 } r.hmset(K.USER.format(uid), user) # Set the TTL for the user account r.expire(K.USER.format(uid), K.EXPIRE_24HRS) return uid # If none of this worked return nothing return None