基于python2.7实现图形密码生成器的实例代码

yipeiwu_com6年前Python基础

具体代码如下所示:

#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'请输入你的密码长度位数!' )
length = wx.TextCtrl(bkg,-1,size=(50,27))
switch = wx.CheckBox(bkg, -1,u'关闭特殊字符',(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密码生成器

'''
随机密码生成器
该生成器用于生成6位随机密码,包含A-Z, a-z , 0-9 , - + = @ $ % & ^
'''
import random
#定义密码生成函数
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))

总结

以上所述是小编给大家介绍的python2.7实现图形密码生成器的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于Python设计】网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

相关文章

对python csv模块配置分隔符和引用符详解

如下所示: file = open('./abc.csv') csv.reader(file, delimiter=',', quotechar='"') 说明:delimiter...

Python注释、分支结构、循环结构、伪“选择结构”用法实例分析

Python注释、分支结构、循环结构、伪“选择结构”用法实例分析

本文实例讲述了Python注释、分支结构、循环结构、伪“选择结构”用法。分享给大家供大家参考,具体如下: 注释: python使用#作为行注释符,使用三引号作为多行注释符 分支结构:...

Python version 2.7 required, which was not found in the registry

Python version 2.7 required, which was not found in the registry

安装PIL库的时候,直接提示:Python version 2.7 required, which was not found in the registry。 如图: 大意是说找不到...

pandas DataFrame行或列的删除方法的实现示例

pandas DataFrame行或列的删除方法的实现示例

此文我们继续围绕DataFrame介绍相关操作。 平时在用DataFrame时候,删除操作用的不太多,基本是从源DataFrame中筛选数据,组成一个新的DataFrame再继续操作。...

Python中使用摄像头实现简单的延时摄影技术

Python中使用摄像头实现简单的延时摄影技术

延时摄影(英语:Time-lapse photography)是以一种较低的帧率拍 下图像或者视频,然后用正常或者较快的速率播放画面的摄影技术。在一段延时摄影视频中,物体或者景物缓慢变化...