This is a simple password generator.
- Providing First and Last Name, then click Get Password! to generate the password
- Line3, 4: you can change the combination here
- Line20 - line25: Use 4 digits of last name to generat the numbers in password
- Line27 - line28: Get the digits for the given alphabet
- Line57: Use lambda to pass multiple parameters
- import wx
- ALP = "HIJKLMNOPQRSTUVWXYZABCDEFG "
- NBR = "456789012345678901234567897"
- KEY = dict(zip(ALP, NBR))
- def getpass(event, firstname, lastname):
- password = ''
- # Input both name are required
- if firstname == '' or lastname == '':
- passText.SetValue('Input both first and last name !')
- else:
- firstname = firstname.upper()
- lastname = lastname.upper()
- length = len(lastname)
- # Fill in blank for the short last name
- if length < 4:
- lasttemp = lastname + ' '
- else:
- lasttemp = lastname
- last4 = lasttemp[0:4]
- for i in last4:
- password += KEY[i]
- passText.SetValue('Password: ' + firstname + password)
- if __name__ == '__main__':
- app = wx.App()
- win = wx.Frame(None, title='Password Generator',
- size = (300, 200), style=wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX)
- bkg = wx.Panel(win)
- font = wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
- bkg.SetFont(font)
- firstTexts = wx.StaticText(bkg, -1, 'First Name: ', size=(90, 22))
- firstTextc = wx.TextCtrl(bkg, -1, size=(200, 22))
- hboxf = wx.BoxSizer()
- hboxf.Add(firstTexts, proportion=0, flag=wx.ALL, border=0)
- hboxf.Add(firstTextc, proportion=0, flag=wx.ALL, border=0)
- lastTexts = wx.StaticText(bkg, -1, 'Last Name: ', size=(90, 22))
- lastTextc = wx.TextCtrl(bkg, -1, size=(200, 22))
- hboxl = wx.BoxSizer()
- hboxl.Add(lastTexts, proportion=0, flag=wx.ALL, border=0)
- hboxl.Add(lastTextc, proportion=0, flag=wx.ALL, border=0)
- submitButton = wx.Button(bkg, label='Get Password!', size=(290, 22))
- submitButton.Bind(wx.EVT_BUTTON,
- lambda event: getpass(event, firstTextc.GetValue(), lastTextc.GetValue()))
- passText = wx.TextCtrl(bkg, -1, '', style=wx.TE_READONLY|wx.BORDER_NONE, size=(290, 22))
- hboxp = wx.BoxSizer()
- hboxp.Add(passText, proportion=0, flag=wx.ALL, border=0)
- vbox = wx.BoxSizer(wx.VERTICAL)
- vbox.Add(hboxf, proportion=0, flag=wx.EXPAND|wx.ALL, border=5)
- vbox.Add(hboxl, proportion=0, flag=wx.EXPAND|wx.ALL, border=5)
- vbox.Add(submitButton, proportion=0, flag=wx.ALL, border=5)
- vbox.Add(hboxp, proportion=0, flag=wx.EXPAND|wx.ALL, border=5)
- bkg.SetSizer(vbox)
- win.Show()
- app.MainLoop()
No comments:
Post a Comment