Kxffie

Python Password Generator v3

Jan 29th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. from rich.console import Console
  2. from rich.markdown import Markdown
  3. from rich.progress import track
  4. from rich.theme import Theme
  5.  
  6. from tinydb import TinyDB
  7. db = TinyDB('./db.json')
  8.  
  9. import time
  10. import random
  11. import string
  12. import json
  13.  
  14. custom_theme = Theme({"green": "green", "red": "red"})
  15.  
  16. console = Console()
  17. MARKDOWN = """
  18. # Kxffie's Password Generator v3
  19.  
  20. ## Created by Kxffie\t[Kxffiehub.xyz](https://www.kxffiehub.xyz)
  21. """
  22. md = Markdown(MARKDOWN)
  23. console.print(md)
  24.  
  25. def profiles():
  26. f = open ('./db.json', "r")
  27. data = json.loads(f.read())
  28. profiles.finalJSON = json.dumps(data, indent=2)
  29. f.close()
  30. print(profiles.finalJSON)
  31.  
  32. def createPass():
  33. createPass.profileName = input("\nWhat profile would you want to save this to? (i.e. Minecraft Password): ")
  34. createPass.passLimit = int(input("How long do you want your password(s) to be: "))
  35. createPass.options = int(input("Options:\n"+"\t1. Just Letters \t2. Letters & Numbers \t3. Letters, Numbers & Punctuation: "))
  36. if(createPass.options == 1):
  37. createPass.randomChar = ''.join(random.sample(string.ascii_letters, k=createPass.passLimit))
  38. elif(createPass.options == 2):
  39. createPass.randomChar = ''.join(random.sample(string.ascii_letters + string.digits + string.octdigits, k=createPass.passLimit))
  40. elif(createPass.options == 3):
  41. createPass.randomChar = ''.join(random.sample(string.ascii_letters + string.punctuation + string.hexdigits + string.octdigits + string.digits, k=createPass.passLimit))
  42.  
  43. def generated():
  44. console.print("\n:closed_lock_with_key: Password Generated! :closed_lock_with_key:", style="bold green")
  45. time.sleep(0.75)
  46. console.print("[red]Password: [/red]" + createPass.randomChar)
  47. answerSave = input("Do you want to save this info? ")
  48. if(answerSave == "yes"):
  49. db.insert({'profile': createPass.profileName, 'password': createPass.randomChar})
  50. console.print("[green]Password " + createPass.randomChar + " Saved! [/green]")
  51.  
  52. def profileManage():
  53. answerManageOptions = input("Options:\n\t1. Delete All Profiles (irreversible): ")
  54. if(answerManageOptions == "1"):
  55. db.truncate()
  56.  
  57. def start():
  58. answer = input("Options:\n\t1. Look at profiles/passwords\t2. Manage Profiles\t3. Create new profile/password: ")
  59. if(answer == "1"):
  60. profiles()
  61. time.sleep(0.5)
  62. input("Press enter to exit...")
  63. if(answer == "2"):
  64. profileManage()
  65. time.sleep(0.5)
  66. input("Press enter to exit...")
  67. if(answer == "3"):
  68. createPass()
  69. generated()
  70.  
  71. time.sleep(1)
  72. answer = input("Do you want to create another password? ")
  73. if(answer == "yes"):
  74. createPass()
  75. generated()
  76. else:
  77. time.sleep(0.5)
  78. input("Press enter to exit...")
  79.  
  80. start()
Advertisement
Add Comment
Please, Sign In to add comment