Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit cdbdd0f

Browse files
committed
🚀 Update Update!
Rewritten everything lol Short changelog: - Added translations - Changed first input to be lowercase - Added custom errors - And more! Full changelog here: https://github.com/KwiatekMiki/passnpingenerator/releases/tag/v1.0
1 parent 01d893e commit cdbdd0f

File tree

5 files changed

+146
-28
lines changed

5 files changed

+146
-28
lines changed

chars.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~

lang/en.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"menu": {
3+
"what": "What do you want to generate?",
4+
"tip": "P̲assword/Pi̲n/N̲ick"
5+
},
6+
"letters": {
7+
"pass": "p",
8+
"pin": "i",
9+
"nick": "n"
10+
},
11+
"password": {
12+
"howlong": "How long password do you need?",
13+
"your": "Your password is"
14+
},
15+
"pin": {
16+
"howlong": "How long PIN do you need?",
17+
"your": "Your PIN is"
18+
},
19+
"nick": {
20+
"soonTM": "Coming soon!"
21+
},
22+
"wronglength": "Wrong length.",
23+
"notint": "Length is not a number."
24+
}

lang/es.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"menu": {
3+
"what": "¿Qué deseas generar?",
4+
"tip": "C̲ontraseña/P̲in/A̲podo"
5+
},
6+
"letters": {
7+
"pass": "c",
8+
"pin": "p",
9+
"nick": "a"
10+
},
11+
"password": {
12+
"howlong": "¿Cuántos caracteres debe tener la contraseña?",
13+
"your": "Tu contraseña es"
14+
},
15+
"pin": {
16+
"howlong": "¿Cuántos dígitos debe tener el PIN?",
17+
"your": "Tu PIN es"
18+
},
19+
"nick": {
20+
"soonTM": "¡Próximamente!"
21+
},
22+
"wronglength": "Longitud incorrecta.",
23+
"notint": "La longitud no es un número."
24+
}

lang/pl.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"menu": {
3+
"what": "Co chcesz wygenerować?",
4+
"tip": "H̲asło/P̲in/N̲ick"
5+
},
6+
"letters": {
7+
"pass": "h",
8+
"pin": "p",
9+
"nick": "n"
10+
},
11+
"password": {
12+
"howlong": "Jak długie hasło potrzebujesz?",
13+
"your": "Twoje hasło to"
14+
},
15+
"pin": {
16+
"howlong": "Jak długi PIN potrzebujesz?",
17+
"your": "Twój PIN to"
18+
},
19+
"nick": {
20+
"soonTM": "Wkrótce!"
21+
},
22+
"wronglength": "Zła długość.",
23+
"notint": "Długość nie jest numerem."
24+
}

main.py

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,73 @@
1-
# No comments in english version...
2-
import string, secrets, os
3-
clearthis = lambda: os.system('cls, clear')
4-
5-
a = string.ascii_letters
6-
b = string.digits
7-
print("=====================")
8-
print("𝚙𝚊𝚜𝚜𝚗𝚙𝚒𝚗𝚐𝚎𝚗")
9-
print("=====================")
10-
11-
c = input("What do you want to receive? [P̲(assword)/(P)i̲(n)/N̲(ick)]: ")
12-
13-
if c == "P" or c == "p":
14-
d = input("What length password do you need? [infinite range]: ")
15-
e = ''.join(secrets.choice (a) for i in range(int(d)))
16-
clearthis()
17-
print("Your password is:")
18-
print(e)
19-
20-
if c == "I" or c == "i":
21-
d = input("What length of PIN do you need? [infinite range]: ")
22-
f = ''.join(secrets.choice (b) for i in range(int(d)))
23-
clearthis()
24-
print("Your PIN is:")
25-
print(f)
26-
27-
if c == "N" or c == "n":
28-
print("Soon 👀")
1+
import secrets, ctypes
2+
import json, os, locale
3+
4+
if not os.path.exists(f"./chars.txt"):
5+
raise FileNotFoundError("Can't find chars.txt. Did you run this in a correct folder?")
6+
7+
with open(f'chars.txt', 'r', encoding='utf-8') as f:
8+
chars = f.read()
9+
10+
# Check language and translate this code
11+
windll = ctypes.windll.kernel32
12+
oglang = locale.windows_locale[windll.GetUserDefaultUILanguage()] # With help of StackOverflow [https://stackoverflow.com/a/25691701] and ChatGPT!
13+
oslang = oglang.split("_")[0]
14+
15+
if not os.path.exists(f"./lang"):
16+
FileNotFoundError("Can't find 'lang' folder. Did you run this in a correct folder?")
17+
18+
if not os.path.exists(f"./lang/{oslang}.json"):
19+
print("Can't find a translation for your Windows language, using English.")
20+
oslang = "en"
21+
22+
with open(f'./lang/{oslang}.json', 'r', encoding='utf-8') as f:
23+
trans = json.load(f)
24+
25+
menu = trans["menu"]
26+
lets = trans["letters"]
27+
passt = trans["password"]
28+
pint = trans["pin"]
29+
nickt = trans["nick"]
30+
31+
# Function to shorten the code
32+
def strtoint(l):
33+
try:
34+
return int(l)
35+
except ValueError:
36+
raise ValueError(trans["notint"])
37+
except:
38+
raise TypeError("Something went wrong.")
39+
40+
def checklen(l, min, max):
41+
l = int(l)
42+
if l > max or l < min:
43+
raise ValueError(trans["wronglength"])
44+
45+
# Main
46+
print("""
47+
█▀█ ▄▀█ █▀ █▀ █▄ █ █▀█ █ █▄ █
48+
█▀▀ █▀█ ▄█ ▄█ █ ▀█ █▀▀ █ █ ▀█
49+
by KwiatekMiki
50+
""")
51+
52+
what = input(f"{menu['what']} [{menu['tip']}]: ").lower()
53+
54+
if what == lets["pass"]:
55+
length = input(f"{passt['howlong']} [4-100]: ")
56+
strtoint(length)
57+
checklen(length, 4, 100)
58+
59+
passwd = ''.join(secrets.choice(chars) for i in range(int(length)))
60+
print(f"{passt['your']}: {passwd}")
61+
62+
elif what == lets["pin"]:
63+
length = strtoint(input(f"{passt['howlong']} [4-10]: "))
64+
checklen(length, 4, 10)
65+
66+
if length > 10 or length < 4:
67+
raise ValueError(trans["wronglength"])
68+
69+
pin = ''.join(secrets.choice("1234567890") for i in range(int(length)))
70+
print(f"{pint['your']}: {pin}")
71+
72+
elif what == lets["nick"]:
73+
print(nickt["soonTM"])

0 commit comments

Comments
 (0)