|
| 1 | +#---------------------------------------------------------------- |
| 2 | +# Name: PasswordGenerator.py |
| 3 | +# Purpose: Password Generator built with DelphiFMX GUI Framework |
| 4 | +# |
| 5 | +# Author: Shaun Roselt |
| 6 | +# |
| 7 | +# Created: 26/02/2023 |
| 8 | +# License: MIT - Free to reuse and modify as you see fit. |
| 9 | +#---------------------------------------------------------------- |
| 10 | + |
| 11 | +import os |
| 12 | +import random |
| 13 | +from delphifmx import * |
| 14 | + |
| 15 | +class frmMain(Form): |
| 16 | + |
| 17 | + def __init__(self, owner): |
| 18 | + self.Caption = 'Password Generator' |
| 19 | + self.Width = 1000 |
| 20 | + self.Height = 900 |
| 21 | + self.Position = "ScreenCenter" |
| 22 | + self.OnShow = self.Form_OnShow |
| 23 | + |
| 24 | + self.layBottom = Layout(self) |
| 25 | + self.layBottom.Parent = self |
| 26 | + self.layBottom.Align = "Client" |
| 27 | + self.layBottom.Padding.Top = 20 |
| 28 | + self.layBottom.Padding.Right = 20 |
| 29 | + self.layBottom.Padding.Bottom = 20 |
| 30 | + self.layBottom.Padding.Left = 20 |
| 31 | + |
| 32 | + self.memTitleOutput = Label(self) |
| 33 | + self.memTitleOutput.Parent = self.layBottom |
| 34 | + self.memTitleOutput.Text = "Passwords" |
| 35 | + self.memTitleOutput.Align = "Top" |
| 36 | + self.memTitleOutput.Height = 36 |
| 37 | + self.memTitleOutput.StyledSettings = "" |
| 38 | + self.memTitleOutput.TextSettings.Font.Size = 20 |
| 39 | + |
| 40 | + self.btnRefresh = Button(self) |
| 41 | + self.btnRefresh.Parent = self.memTitleOutput |
| 42 | + self.btnRefresh.Text = "Refresh" |
| 43 | + self.btnRefresh.Align = "Right" |
| 44 | + self.btnRefresh.Width = 75 |
| 45 | + self.btnRefresh.Margins.Top = 1 |
| 46 | + self.btnRefresh.Margins.Right = 3 |
| 47 | + self.btnRefresh.Margins.Bottom = 1 |
| 48 | + self.btnRefresh.TextSettings.HorzAlign = "Center" |
| 49 | + self.btnRefresh.OnClick = self.Refresh_OnClick |
| 50 | + |
| 51 | + self.btnOutputCopyToClipboard = Button(self) |
| 52 | + self.btnOutputCopyToClipboard.Parent = self.memTitleOutput |
| 53 | + self.btnOutputCopyToClipboard.Text = "Copy to Clipboard" |
| 54 | + self.btnOutputCopyToClipboard.Align = "MostRight" |
| 55 | + self.btnOutputCopyToClipboard.Width = 135 |
| 56 | + self.btnOutputCopyToClipboard.Margins.Top = 1 |
| 57 | + self.btnOutputCopyToClipboard.Margins.Right = 1 |
| 58 | + self.btnOutputCopyToClipboard.Margins.Bottom = 1 |
| 59 | + self.btnOutputCopyToClipboard.TextSettings.HorzAlign = "Center" |
| 60 | + self.btnOutputCopyToClipboard.OnClick = self.CopyToClipboard_OnClick |
| 61 | + |
| 62 | + self.memOutput = Memo(self) |
| 63 | + self.memOutput.Parent = self.layBottom |
| 64 | + self.memOutput.Align = "Client" |
| 65 | + |
| 66 | + self.layTop = Layout(self) |
| 67 | + self.layTop.Parent = self |
| 68 | + self.layTop.Align = "Top" |
| 69 | + self.layTop.Padding.Top = 20 |
| 70 | + self.layTop.Padding.Right = 20 |
| 71 | + self.layTop.Padding.Bottom = 20 |
| 72 | + self.layTop.Padding.Left = 20 |
| 73 | + self.layTop.Height = 369 |
| 74 | + |
| 75 | + self.lblConfiguration = Label(self) |
| 76 | + self.lblConfiguration.Parent = self.layTop |
| 77 | + self.lblConfiguration.Text = "Configuration" |
| 78 | + self.lblConfiguration.Align = "MostTop" |
| 79 | + self.lblConfiguration.Height = 30 |
| 80 | + self.lblConfiguration.StyledSettings = "" |
| 81 | + self.lblConfiguration.TextSettings.Font.Size = 20 |
| 82 | + |
| 83 | + self.layAmount = Rectangle(self) |
| 84 | + self.layAmount.Parent = self.layTop |
| 85 | + self.layAmount.Align = "Top" |
| 86 | + self.layAmount.Height = 72 |
| 87 | + self.layAmount.Margins.Bottom = 6 |
| 88 | + self.layAmount.Padding.Top = 12 |
| 89 | + self.layAmount.Padding.Right = 12 |
| 90 | + self.layAmount.Padding.Bottom = 12 |
| 91 | + self.layAmount.Padding.Left = 12 |
| 92 | + self.layAmount.Stroke.Kind = "None" |
| 93 | + self.layAmount.Fill.Color = "x4B000000" |
| 94 | + self.layAmount.XRadius = 8 |
| 95 | + self.layAmount.YRadius = 8 |
| 96 | + |
| 97 | + self.layAmountTitleDescription = Layout(self) |
| 98 | + self.layAmountTitleDescription.Parent = self.layAmount |
| 99 | + self.layAmountTitleDescription.Align = "Client" |
| 100 | + |
| 101 | + self.lblAmountTitle = Label(self) |
| 102 | + self.lblAmountTitle.Parent = self.layAmountTitleDescription |
| 103 | + self.lblAmountTitle.Text = "Amount" |
| 104 | + self.lblAmountTitle.Align = "Top" |
| 105 | + self.lblAmountTitle.Height = 24 |
| 106 | + self.lblAmountTitle.StyledSettings = "" |
| 107 | + self.lblAmountTitle.TextSettings.Font.Size = 18 |
| 108 | + |
| 109 | + self.lblAmountDescription = Label(self) |
| 110 | + self.lblAmountDescription.Parent = self.layAmountTitleDescription |
| 111 | + self.lblAmountDescription.Text = "Select how many passwords you want" |
| 112 | + self.lblAmountDescription.Align = "Client" |
| 113 | + self.lblAmountDescription.StyledSettings = "" |
| 114 | + self.lblAmountDescription.TextSettings.Font.Size = 14 |
| 115 | + |
| 116 | + self.sbAmount = SpinBox(self) |
| 117 | + self.sbAmount.Parent = self.layAmount |
| 118 | + self.sbAmount.Align = "Right" |
| 119 | + self.sbAmount.Width = 140 |
| 120 | + self.sbAmount.Value = 20 |
| 121 | + self.sbAmount.Min = 1 |
| 122 | + self.sbAmount.Max = 1000 |
| 123 | + self.sbAmount.OnChange = self.Refresh_OnClick |
| 124 | + |
| 125 | + self.layPasswordLength = Rectangle(self) |
| 126 | + self.layPasswordLength.Parent = self.layTop |
| 127 | + self.layPasswordLength.Align = "Top" |
| 128 | + self.layPasswordLength.Height = 72 |
| 129 | + self.layPasswordLength.Margins.Bottom = 6 |
| 130 | + self.layPasswordLength.Padding.Top = 12 |
| 131 | + self.layPasswordLength.Padding.Right = 12 |
| 132 | + self.layPasswordLength.Padding.Bottom = 12 |
| 133 | + self.layPasswordLength.Padding.Left = 12 |
| 134 | + self.layPasswordLength.Stroke.Kind = "None" |
| 135 | + self.layPasswordLength.Fill.Color = "x4B000000" |
| 136 | + self.layPasswordLength.XRadius = 8 |
| 137 | + self.layPasswordLength.YRadius = 8 |
| 138 | + |
| 139 | + self.layPasswordLengthTitleDescription = Layout(self) |
| 140 | + self.layPasswordLengthTitleDescription.Parent = self.layPasswordLength |
| 141 | + self.layPasswordLengthTitleDescription.Align = "Client" |
| 142 | + |
| 143 | + self.lblPasswordLengthTitle = Label(self) |
| 144 | + self.lblPasswordLengthTitle.Parent = self.layPasswordLengthTitleDescription |
| 145 | + self.lblPasswordLengthTitle.Text = "Password Length" |
| 146 | + self.lblPasswordLengthTitle.Align = "Top" |
| 147 | + self.lblPasswordLengthTitle.Height = 24 |
| 148 | + self.lblPasswordLengthTitle.StyledSettings = "" |
| 149 | + self.lblPasswordLengthTitle.TextSettings.Font.Size = 18 |
| 150 | + |
| 151 | + self.lblPasswordLengthDescription = Label(self) |
| 152 | + self.lblPasswordLengthDescription.Parent = self.layPasswordLengthTitleDescription |
| 153 | + self.lblPasswordLengthDescription.Text = "Select the length of the password" |
| 154 | + self.lblPasswordLengthDescription.Align = "Client" |
| 155 | + self.lblPasswordLengthDescription.StyledSettings = "" |
| 156 | + self.lblPasswordLengthDescription.TextSettings.Font.Size = 14 |
| 157 | + |
| 158 | + self.sbPasswordLength = SpinBox(self) |
| 159 | + self.sbPasswordLength.Parent = self.layPasswordLength |
| 160 | + self.sbPasswordLength.Align = "Right" |
| 161 | + self.sbPasswordLength.Width = 140 |
| 162 | + self.sbPasswordLength.Value = 20 |
| 163 | + self.sbPasswordLength.Min = 1 |
| 164 | + self.sbPasswordLength.Max = 1000 |
| 165 | + self.sbPasswordLength.OnChange = self.Refresh_OnClick |
| 166 | + |
| 167 | + self.laySpecialCharacters = Rectangle(self) |
| 168 | + self.laySpecialCharacters.Parent = self.layTop |
| 169 | + self.laySpecialCharacters.Align = "Top" |
| 170 | + self.laySpecialCharacters.Height = 72 |
| 171 | + self.laySpecialCharacters.Margins.Bottom = 6 |
| 172 | + self.laySpecialCharacters.Padding.Top = 12 |
| 173 | + self.laySpecialCharacters.Padding.Right = 12 |
| 174 | + self.laySpecialCharacters.Padding.Bottom = 12 |
| 175 | + self.laySpecialCharacters.Padding.Left = 12 |
| 176 | + self.laySpecialCharacters.Stroke.Kind = "None" |
| 177 | + self.laySpecialCharacters.Fill.Color = "x4B000000" |
| 178 | + self.laySpecialCharacters.XRadius = 8 |
| 179 | + self.laySpecialCharacters.YRadius = 8 |
| 180 | + |
| 181 | + self.laySpecialCharactersTitleDescription = Layout(self) |
| 182 | + self.laySpecialCharactersTitleDescription.Parent = self.laySpecialCharacters |
| 183 | + self.laySpecialCharactersTitleDescription.Align = "Client" |
| 184 | + |
| 185 | + self.lblSpecialCharactersTitle = Label(self) |
| 186 | + self.lblSpecialCharactersTitle.Parent = self.laySpecialCharactersTitleDescription |
| 187 | + self.lblSpecialCharactersTitle.Text = "Special Characters" |
| 188 | + self.lblSpecialCharactersTitle.Align = "Top" |
| 189 | + self.lblSpecialCharactersTitle.Height = 24 |
| 190 | + self.lblSpecialCharactersTitle.StyledSettings = "" |
| 191 | + self.lblSpecialCharactersTitle.TextSettings.Font.Size = 18 |
| 192 | + |
| 193 | + self.lblSpecialCharactersDescription = Label(self) |
| 194 | + self.lblSpecialCharactersDescription.Parent = self.laySpecialCharactersTitleDescription |
| 195 | + self.lblSpecialCharactersDescription.Text = "Select whether you want to use special characters or not" |
| 196 | + self.lblSpecialCharactersDescription.Align = "Client" |
| 197 | + self.lblSpecialCharactersDescription.StyledSettings = "" |
| 198 | + self.lblSpecialCharactersDescription.TextSettings.Font.Size = 14 |
| 199 | + |
| 200 | + self.lblSwitchSpecialCharacters = Label(self) |
| 201 | + self.lblSwitchSpecialCharacters.Parent = self.laySpecialCharacters |
| 202 | + self.lblSwitchSpecialCharacters.Text = "On" |
| 203 | + self.lblSwitchSpecialCharacters.Align = "Right" |
| 204 | + self.lblSwitchSpecialCharacters.StyledSettings = "" |
| 205 | + self.lblSwitchSpecialCharacters.TextSettings.Font.Size = 18 |
| 206 | + self.lblSwitchSpecialCharacters.TextSettings.HorzAlign = "Trailing" |
| 207 | + self.lblSwitchSpecialCharacters.Margins.Right = 8 |
| 208 | + self.lblSwitchSpecialCharacters.Width = 72 |
| 209 | + |
| 210 | + self.SpecialCharactersSwitch = Switch(self) |
| 211 | + self.SpecialCharactersSwitch.Parent = self.laySpecialCharacters |
| 212 | + self.SpecialCharactersSwitch.Align = "MostRight" |
| 213 | + self.SpecialCharactersSwitch.isChecked = True |
| 214 | + self.SpecialCharactersSwitch.Width = 72 |
| 215 | + self.SpecialCharactersSwitch.OnSwitch = self.SpecialCharactersSwitch_OnSwitch |
| 216 | + |
| 217 | + self.layLetterCase = Rectangle(self) |
| 218 | + self.layLetterCase.Parent = self.layTop |
| 219 | + self.layLetterCase.Align = "Top" |
| 220 | + self.layLetterCase.Height = 72 |
| 221 | + self.layLetterCase.Margins.Bottom = 6 |
| 222 | + self.layLetterCase.Padding.Top = 12 |
| 223 | + self.layLetterCase.Padding.Right = 12 |
| 224 | + self.layLetterCase.Padding.Bottom = 12 |
| 225 | + self.layLetterCase.Padding.Left = 12 |
| 226 | + self.layLetterCase.Stroke.Kind = "None" |
| 227 | + self.layLetterCase.Fill.Color = "x4B000000" |
| 228 | + self.layLetterCase.XRadius = 8 |
| 229 | + self.layLetterCase.YRadius = 8 |
| 230 | + |
| 231 | + self.layLetterCaseTitleDescription = Layout(self) |
| 232 | + self.layLetterCaseTitleDescription.Parent = self.layLetterCase |
| 233 | + self.layLetterCaseTitleDescription.Align = "Client" |
| 234 | + |
| 235 | + self.lblLetterCaseTitle = Label(self) |
| 236 | + self.lblLetterCaseTitle.Parent = self.layLetterCaseTitleDescription |
| 237 | + self.lblLetterCaseTitle.Text = "Letter Case" |
| 238 | + self.lblLetterCaseTitle.Align = "Top" |
| 239 | + self.lblLetterCaseTitle.Height = 24 |
| 240 | + self.lblLetterCaseTitle.StyledSettings = "" |
| 241 | + self.lblLetterCaseTitle.TextSettings.Font.Size = 18 |
| 242 | + |
| 243 | + self.lblLetterCaseDescription = Label(self) |
| 244 | + self.lblLetterCaseDescription.Parent = self.layLetterCaseTitleDescription |
| 245 | + self.lblLetterCaseDescription.Text = "Select which letter case you want to use" |
| 246 | + self.lblLetterCaseDescription.Align = "Client" |
| 247 | + self.lblLetterCaseDescription.StyledSettings = "" |
| 248 | + self.lblLetterCaseDescription.TextSettings.Font.Size = 14 |
| 249 | + |
| 250 | + self.cbLetterCase = ComboBox(self) |
| 251 | + self.cbLetterCase.Parent = self.layLetterCase |
| 252 | + self.cbLetterCase.Align = "Right" |
| 253 | + self.cbLetterCase.Width = 140 |
| 254 | + self.cbLetterCase.Items.Add("Regular") |
| 255 | + self.cbLetterCase.Items.Add("lower") |
| 256 | + self.cbLetterCase.Items.Add("UPPER") |
| 257 | + self.cbLetterCase.ItemIndex = 0 |
| 258 | + self.cbLetterCase.OnChange = self.Refresh_OnClick |
| 259 | + |
| 260 | + def GenerateRandomPassword(self): |
| 261 | + self.memOutput.Lines.Clear() |
| 262 | + characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
| 263 | + if self.SpecialCharactersSwitch.isChecked: |
| 264 | + characters += "!@#$%^&*()_+-=[]{}|;:,.<>/?" |
| 265 | + |
| 266 | + for i in range(round(self.sbAmount.Value)): |
| 267 | + password = "" |
| 268 | + for j in range(round(self.sbPasswordLength.Value)): |
| 269 | + password += random.choice(characters) |
| 270 | + self.memOutput.Lines.Add(password) |
| 271 | + |
| 272 | + |
| 273 | + def SpecialCharactersSwitch_OnSwitch(self, sender): |
| 274 | + if sender.isChecked: |
| 275 | + self.lblSwitchSpecialCharacters.Text = "On" |
| 276 | + else: |
| 277 | + self.lblSwitchSpecialCharacters.Text = "Off" |
| 278 | + |
| 279 | + self.GenerateRandomPassword() |
| 280 | + |
| 281 | + def Refresh_OnClick(self, sender): |
| 282 | + self.GenerateRandomPassword() |
| 283 | + |
| 284 | + def CopyToClipboard_OnClick(self, sender): |
| 285 | + self.memOutput.SelectAll() |
| 286 | + self.memOutput.CopyToClipboard() |
| 287 | + |
| 288 | + def Form_OnShow(self, sender): |
| 289 | + self.GenerateRandomPassword() |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | +def main(): |
| 294 | + Application.Initialize() |
| 295 | + Application.Title = 'Password Generator' |
| 296 | + Application.MainForm = frmMain(Application) |
| 297 | + Application.MainForm.Show() |
| 298 | + Application.Run() |
| 299 | + Application.MainForm.Destroy() |
| 300 | + |
| 301 | +if __name__ == '__main__': |
| 302 | + main() |
0 commit comments