基于python2.7實現(xiàn)圖形密碼生成器的實例代碼
具體代碼如下所示:
#coding:utf8
import random,wx
def password(event):
a = [chr(i) for i in range(97,123)]
b = [chr(i) for i in range(65,91)]
c = ['0','1','2','3','4','5','6','7','8','9']
d = ['!','@','#','$','%','^','&','*','(',')','=','_','+','/','?']
set1 = a + b + c + d
set2 = a + b + c
num = int(length.GetValue())
if switch.GetValue() == 0:
passwd = ''.join(random.sample(set1,num))
contents.SetValue(passwd)
else:
passwd = ''.join(random.sample(set2,num))
contents.SetValue(passwd)
app = wx.App()
win = wx.Frame(None,-1,title=u'密碼生成器',size=(480,200))
bkg = wx.Panel(win,-1)
# tt = wx.StaticText(bkg,-1,u'屏蔽輸入字符')
# delete = wx.TextCtrl(bkg,-1)
right = wx.Button(bkg,-1,label=u'確定生成')
right.Bind(wx.EVT_BUTTON,password)
stxt = wx.StaticText(bkg,-1,u'請輸入你的密碼長度位數(shù)!' )
length = wx.TextCtrl(bkg,-1,size=(50,27))
switch = wx.CheckBox(bkg, -1,u'關(guān)閉特殊字符',(150, 20))
sobx = wx.BoxSizer()
sobx.Add(stxt,proportion=0,flag=wx.ALL,border=5)
sobx.Add(length,proportion=1,border=5)
sobx.Add(switch,proportion=0,flag=wx.ALL | wx.ALIGN_RIGHT,border=5)
sobx.Add(right,proportion=0,flag=wx.EXPAND,border=5)
contents = wx.TextCtrl(bkg,-1)
cobx = wx.BoxSizer()
cobx.Add(contents,proportion=1,flag=wx.EXPAND,border=5)
dobx = wx.BoxSizer()
# dobx.Add(delete,proportion=1,flag=wx.ALL,border=5)
robx = wx.BoxSizer(wx.VERTICAL)
robx.Add(cobx,proportion=1,flag=wx.EXPAND | wx.ALL,border=5)
robx.Add(sobx,proportion=0,flag=wx.ALL,border=5)
# robx.Add(dobx,proportion=0,flag=wx.EXPAND,border=5)
bkg.SetSizer(robx)
win.Show()
app.MainLoop()
ps:下面看下python密碼生成器
'''
隨機(jī)密碼生成器
該生成器用于生成6位隨機(jī)密碼,包含A-Z, a-z , 0-9 , - + = @ $ % & ^
'''
import random
#定義密碼生成函數(shù)
def pass_generator(n):
lst1 = list(range(65,91))
lst2 = list(range(97,123))
lst3 = list(range(10))
lst4 = ['+','-','=','@','#','$','%','^']
s1 = ''.join(chr(c) for c in lst1)
s2 = ''.join(chr(c) for c in lst2)
s3 = ''.join(str(i) for i in lst3)
s4 = ''.join( c for c in lst4)
s = s1 + s2 + s3 + s4
p = ''
for _ in range(n):
p += random.choice(s)
return p
print(pass_generator(32))
總結(jié)
以上所述是小編給大家介紹的python2.7實現(xiàn)圖形密碼生成器的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
完美解決Python matplotlib繪圖時漢字顯示不正常的問題
今天小編就為大家分享一篇完美解決Python matplotlib繪圖時漢字顯示不正常的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-01-01
python實現(xiàn)mysql的讀寫分離及負(fù)載均衡
這篇文章主要介紹了python實現(xiàn)mysql的讀寫分離及負(fù)載均衡 ,需要的朋友可以參考下2018-02-02
Python錯誤提示:[Errno 24] Too many open files的分析與解決
這篇文章主要給大家介紹了Python中出現(xiàn)錯誤提示:[Errno 24] Too many open files的分析與解決,需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02
簡單學(xué)習(xí)Python多進(jìn)程Multiprocessing
這篇文章主要和大家一起簡單的學(xué)習(xí)Python多進(jìn)程Multiprocessing ,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08
python中windows鏈接linux執(zhí)行命令并獲取執(zhí)行狀態(tài)的問題小結(jié)
這篇文章主要介紹了python中windows鏈接linux執(zhí)行命令并獲取執(zhí)行狀態(tài),由于工具是pyqt寫的所以牽扯到用python鏈接linux的問題,這里記錄一下一些碰到的問題,需要的朋友可以參考下2022-11-11

