在用戶找回密碼功能里面, 需要生成隨機字符串, 在python中其實很簡單, 先定義一個字符串變量, 包含密碼中你想生成隨機字符串使用的所有字符.
list = 'abcdefghijklmnopqrstuvwxyz$&()#@'
import string, random
password = string.join(random.sample(list, 6), sep='')
user.set_password(password)
注意需要使用random和string模塊, 前者是用來獲取隨機字符, 后者是把list轉化為字符串形式.
posted on 2009-06-08 22:28
周銳 閱讀(633)
評論(0) 編輯 收藏 所屬分類:
Python