Exemplo n.º 1
0
def createUser(db,
               email,
               password,
               firstName=None,
               lastName=None,
               phone=None,
               imageId=None,
               locationId=None,
               affiliation=None,
               isAdmin=False):
    userId = None
    key = util.random_string(10)
    encrypted_password, salt = makePassword(password)

    try:
        userId = db.insert('user',
                           user_key=key,
                           email=email,
                           password=encrypted_password,
                           salt=salt,
                           phone=phone,
                           first_name=firstName,
                           last_name=lastName,
                           affiliation=affiliation,
                           image_id=imageId,
                           location_id=locationId,
                           created_datetime=None)

    except Exception, e:
        log.info("*** problem creating user")
        log.error(e)
Exemplo n.º 2
0
def resetPassword(db, userId):
    forgetfulUser = User(db, userId)
    newPassword = util.random_string(10)

    if (forgetfulUser.updatePassword(newPassword)):
        return mMessaging.emailTempPassword(forgetfulUser.email, newPassword)
    else:
        return False
Exemplo n.º 3
0
def resetPassword(db, userId):
    forgetfulUser = User(db, userId)
    newPassword = util.random_string(10)

    if (forgetfulUser.updatePassword(newPassword)):
        return mMessaging.emailTempPassword(forgetfulUser.email, newPassword)
    else:
        return False
Exemplo n.º 4
0
def createUser(db, email, password, firstName = None, lastName = None, phone = None, imageId = None, locationId = None, affiliation = None, isAdmin = False):
    userId = None
    key = util.random_string(10)
    encrypted_password, salt = makePassword(password)

    try:
        userId = db.insert('user', user_key=key,
                                    email=email,
                                    password=encrypted_password,
                                    salt=salt,
                                    phone=phone,
                                    first_name=firstName,
                                    last_name=lastName,
                                    affiliation=affiliation,
                                    image_id=imageId,
                                    location_id=locationId,
                                    created_datetime=None)

    except Exception, e:
        log.info("*** problem creating user")
        log.error(e)
Exemplo n.º 5
0
 def test_random_string(self):
     self.assertEqual(len(util.random_string(12)), 12)
     self.assertEqual(len(re.findall("^[A-Za-z0-9]{12}$", util.random_string(12))), 1)
Exemplo n.º 6
0
def makePassword(password, salt = None):
    if (not salt):
        salt = util.random_string(10)

    hashed_password = hashlib.md5(password + salt).hexdigest()
    return [hashed_password, salt]
Exemplo n.º 7
0
def makePassword(password, salt=None):
    if (not salt):
        salt = util.random_string(10)

    hashed_password = hashlib.md5(password + salt).hexdigest()
    return [hashed_password, salt]