Пример #1
0
def token_generator(is_audio_token=False):
    '''
    Generate an user token string.

    If is_audio_token is False, it a string of 8 alfanumeric characters. We do
    not allow confusing characters: 0,O,I,1.

    If is_audio_token is True, the it generates string of 8 numeric characters.
    The string always starts with a non-zero number, so it's guaranteed to be
    8 characters long (and thus there are 90 million possibilities)
    '''
    if not is_audio_token:
        return get_random_string(8, 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789')
    else: #use only numbers: large numbers (8 chars always)
        return " ".join([get_random_string(2, '123456789') for i in range(4)])
Пример #2
0
    def get_admin_user(self):
        token_id = self.get_secure_cookie("token_id")
        if not  token_id:
            return None
        token = token_id.split("/")[0]
        admin_id =   token_id.split("/")[1]

        db_admin = self.get_admin_by_id( ObjectId(admin_id) )
        if db_admin == None :
            return None

        if db_admin["token"] != token.strip():
            return None

        now_diff = datetime.datetime.utcnow() - db_admin["token_time"]
        #证书超时
        if now_diff > datetime.timedelta(hours =5 ):
            print "证书超时。"
            rand_string = get_random_string()
            self.update_admin_salt(admin_id ,rand_string)
            self.update_admin_token_time(admin_id)
            self.clear_cookie("token")
            self.redirect("/")
        else :
            return db_admin["name"]
Пример #3
0
def create_user(conn):
    c = conn.cursor()
    salt = crypto.get_random_string()
    enpass = crypto.hex_password(PASSWORD)
    c.execute("""
        INSERT INTO users ( salt, username, password, email) VALUES (?,?,?,?)
        """, (salt, USERNAME, enpass, EMAIL))
    conn.commit()
Пример #4
0
def create_user(conn):
    c = conn.cursor()
    salt = crypto.get_random_string()
    enpass = crypto.hex_password(PASSWORD)
    c.execute(
        """
        INSERT INTO users ( salt, username, password, email) VALUES (?,?,?,?)
        """, (salt, USERNAME, enpass, EMAIL))
    conn.commit()
Пример #5
0
def _get_new_csrf_key():
    return get_random_string(TOKEN_LENGTH)
Пример #6
0
def _get_new_csrf_key():
    return get_random_string(TOKEN_LENGTH)
Пример #7
0
             salt VARCHAR(12) NOT NULL, username VARCHAR(50) NOT NULL,
             password VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL);
          """)
c.execute("""CREATE TABLE posts (id INTEGER NOT NULL PRIMARY KEY,
             title VARCHAR(100) NOT NULL, slug VARCHAR(100) NOT NULL,
             content TEXT NOT NULL, tags VARCHAR(255) NOT NULL,
             category VARCHAR(30) NOT NULL, published VARCHAR(30) NOT NULL);
          """)
c.execute("""CREATE TABLE tags (id INTEGER NOT NULL PRIMARY KEY,
             name VARCHAR(50) NOT NULL, post_id INTEGER NOT NULL);
          """)

c.execute("CREATE UNIQUE INDEX users_id ON users(id);")
c.execute("CREATE UNIQUE INDEX posts_id ON posts(id);")
c.execute("CREATE INDEX posts_slug ON posts(slug);")
c.execute("CREATE INDEX tags_name ON tags(name);")
c.execute("CREATE UNIQUE INDEX tags_id ON tags(id);")

print "Start Create User........."

salt = crypto.get_random_string()
enpass= crypto.hex_password(password)

c.execute("INSERT INTO users ( salt, username, password, email) VALUES (?,?,?,?)",
          (salt, username, enpass, email))

conn.commit()
conn.close()

print "DB Create.......!!"