Back to main page
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README4
-rw-r--r--config.py28
-rw-r--r--main.py127
3 files changed, 159 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..ccf6166
--- /dev/null
+++ b/README
@@ -0,0 +1,4 @@
+Func-e Memorable Password Generator
+
+Requires english-words
+ pip install english-words
diff --git a/config.py b/config.py
new file mode 100644
index 0000000..d653fba
--- /dev/null
+++ b/config.py
@@ -0,0 +1,28 @@
+import curses
+class config:
+ # KEYBINDINGS
+
+ # Q
+ key_quit = [81]
+ # h a left
+ key_left = [104, 97, 68]
+ # l d right
+ key_right = [108, 100, 67]
+ # j s down
+ key_down = [106, 115, 66]
+ # k w up
+ key_up = [107, 119, 65]
+ # enter, space
+ key_enter = [curses.KEY_ENTER, 32]
+ # m
+ key_help = [109]
+
+
+ # COLORS
+
+ # default
+ curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
+ # selected
+ curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
+ # info
+ curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..9464e20
--- /dev/null
+++ b/main.py
@@ -0,0 +1,127 @@
+winsizeX = 75
+winsizeY = 20
+
+global show_help
+show_help = False
+password = ""
+
+help_menu = [
+"Press m to toggle help",
+"Navigation:",
+" Arrow keys,",
+" WASD,",
+" HJKL",
+"Press Enter or Space to generate a password",
+"Press Shift-Q to quit"
+]
+
+
+import random
+import curses
+import math
+from english_words import english_words_lower_alpha_set
+
+numbers_list = '0123456789'
+characters_list = '{}[]()!@#$%^&*,./<>?\\|`~-_=+\'\";:'
+
+stdscr = curses.initscr()
+curses.noecho()
+curses.curs_set(0)
+
+height, width = stdscr.getmaxyx()
+
+distanceX = width - winsizeX
+distanceY = height - winsizeY
+
+mainwin = curses.newwin(0, 0, distanceY, distanceX)
+
+mainwin.mvwin(math.floor(distanceY / 2), math.floor(distanceX / 2))
+
+curses.start_color()
+
+from config import config
+
+options = [
+# name value min max
+["Words", 2, 2, 12],
+["Numbers", 0, 0, 12],
+["Special Characters", 0, 0, 12]
+]
+
+global curspos
+curspos = 0 # cursor position
+
+def Left():
+ if options[curspos][1] > options[curspos][2]:
+ options[curspos][1] -= 1
+
+def Right():
+ if options[curspos][1] < options[curspos][3]:
+ options[curspos][1] += 1
+
+def Up():
+ global curspos
+ if curspos > 0:
+ curspos -= 1
+
+def Down():
+ global curspos
+ if curspos < len(options) - 1:
+ curspos += 1
+
+def Generate():
+ global password
+ password = ""
+ new_list = []
+
+ for i in range(options[0][1]):
+ new_list.append(random.choice(list(english_words_lower_alpha_set)))
+ for i in range(options[1][1]):
+ new_list.append(random.choice(list(numbers_list)))
+ for i in range(options[2][1]):
+ new_list.append(random.choice(list(characters_list)))
+
+ random.shuffle(new_list)
+ for item in new_list:
+ password = password + item
+
+def Render():
+ mainwin.clear()
+ mainwin.box()
+
+ mainwin.addstr(1, 1, help_menu[0], curses.color_pair(3))
+ if show_help:
+ for i in range(len(help_menu)):
+ if i == 0:
+ continue
+ mainwin.addstr(i + 1, 1, help_menu[i], curses.color_pair(3))
+ else:
+ for i in range(len(options)):
+ color = 1
+ if i == curspos:
+ mainwin.addstr(i + 2, winsizeX - 3 - len(str(options[i][1])), "<", curses.color_pair(2))
+ mainwin.addstr(i + 2, winsizeX - 2, ">", curses.color_pair(2))
+ color = 2
+ mainwin.addstr(i + 2, 1, options[i][0], curses.color_pair(color))
+ mainwin.addstr(i + 2, winsizeX - 2 - len(str(options[i][1])), str(options[i][1]), curses.color_pair(1))
+ mainwin.addstr(winsizeY - 2, 1, password)
+
+while True:
+ Render()
+ key = mainwin.getch()
+ if key in config.key_quit:
+ break
+ if key in config.key_left:
+ Left()
+ elif key in config.key_right:
+ Right()
+ elif key in config.key_up:
+ Up()
+ elif key in config.key_down:
+ Down()
+ elif key in config.key_enter:
+ Generate()
+ elif key in config.key_help:
+ show_help = not show_help
+
+curses.endwin()