Esempio n. 1
0
def create_session(db, user, from_ip=None):
    '''创建新的会话凭证
    '''
    # 得到新 sid
    while True:
        sid = random_ascii(128)
        c = db.query(Session).filter_by(sid=sid).count()
        if not c:
            break

    # TODO: 删除旧的 session

    session = Session(sid, user, from_ip=from_ip)
    db.add(session)
    db.commit()

    return session
Esempio n. 2
0
 def gen_uid(cls, db):
     while True:
         x = random_ascii(8, ignorecase=True)
         if not db.query(cls.uid).filter_by(uid=x).count():
             break
     return x
Esempio n. 3
0
def enc_login_passwd(plaintext):
    salt = random_ascii(128)
    hsh = _encrypt_password(salt, plaintext)
    enc_password = "******" % (salt, hsh)

    return enc_password
Esempio n. 4
0
 def gen_uid(cls, db):
     while True:
         x = random_ascii(8, ignorecase=True)
         if not db.query(cls.uid).filter_by(uid=x).count():
             break
     return x
Esempio n. 5
0
def enc_login_passwd(plaintext):
    salt = random_ascii(128)
    hsh = _encrypt_password(salt, plaintext)
    enc_password = "******" % (salt, hsh)

    return enc_password