Discuss / Python / 好神奇,哈哈哈

好神奇,哈哈哈

Topic source

不会潘岩

#1 Created at ... [Delete] [Delete and Lock User]

-- coding: utf-8 --

import hashlib, random

def get_md5(s): return hashlib.md5(s.encode('utf-8')).hexdigest()

class User(object): def init(self, username, password): self.username = username self.salt = ''.join([chr(random.randint(48, 122)) for i in range(20)]) self.password = get_md5(password + self.salt) db = { 'michael': User('michael', '123456'), 'bob': User('bob', 'abc999'), 'alice': User('alice', 'alice2008') }

def login(username, password): user = db[username] return user.password == get_md5(password + user.salt)

不会潘岩

#2 Created at ... [Delete] [Delete and Lock User]

不知道如何把这个实例储存起来?可以将实例储存在数据库吗?


  • 1

Reply