Add generate password system

Note that this commit references my IRC configuraton. I'm not checking
it in as I have too many credentials and personal information in it.
When I abstract it sufficiently, I will commit it.
This commit is contained in:
Howard Abrams 2021-11-15 16:18:31 -08:00
parent 669a16ebb9
commit 2669fdaa5b
6 changed files with 590 additions and 2 deletions

View file

@ -26,6 +26,8 @@ This creates [[file:~/.emacs.d/init.el][~/.emacs.d/init.el]] that starts the pro
- [[file:ha-capturing-notes.org][ha-capturing-notes.org]] :: my engineering notebook. - [[file:ha-capturing-notes.org][ha-capturing-notes.org]] :: my engineering notebook.
- [[file:ha-agendas.org][ha-agendas.org]] :: Attempts to "supe-up" my task list. - [[file:ha-agendas.org][ha-agendas.org]] :: Attempts to "supe-up" my task list.
- [[file:ha-email.org][ha-email.org]] :: Reading email using =notmuch= in a *Hey* fashion. - [[file:ha-email.org][ha-email.org]] :: Reading email using =notmuch= in a *Hey* fashion.
- [[file:ha-irc.org][ha-irc.org]] :: Connection to IRC servers using rcirc and bitlbee.
- [[file:ha-passwords.org][ha-passwords.org]] :: Code for generating passwords.
- [[file:ha-programming.org][ha-programming.org]] :: configuration for /all/ programming languages, or at least, the simple ones. - [[file:ha-programming.org][ha-programming.org]] :: configuration for /all/ programming languages, or at least, the simple ones.
*Note:* Other functions and files come from essays written on [[http://www.howardism.org][my blog]]. To help with this, see [[file:support/final-initialize.el][support/final-initialize.el]] file. *Note:* Other functions and files come from essays written on [[http://www.howardism.org][my blog]]. To help with this, see [[file:support/final-initialize.el][support/final-initialize.el]] file.

View file

@ -122,8 +122,8 @@ The following loads the rest of my org-mode literate files. I add them as they a
"ha-programming.org" "ha-programming.org"
"ha-agendas.org" "ha-agendas.org"
"ha-email.org" "ha-email.org"
;; "ha-irc.org" "ha-irc.org"
;; "ha-passwords.org" "ha-passwords.org"
"ha-remoting.org" "ha-remoting.org"
"ha-feed-reader.org" "ha-feed-reader.org"

230
data/adjectives.txt Normal file
View file

@ -0,0 +1,230 @@
adorable
adventurous
aggressive
agreeable
alert
alive
amused
angry
annoyed
annoying
anxious
arrogant
ashamed
attractive
average
awful
bad
beautiful
better
bewildered
bittersweet
blushing
shadowy
black
bloody
blue-eyed
blushing
bored
brainy
brave
breakable
bright
busy
calm
careful
cautious
charming
cheerful
clean
clear
clever
cloudy
clumsy
colorful
combative
comfortable
concerned
condemned
confused
cooperative
courageous
crazy
creepy
crowded
cruel
curious
cute
dangerous
dark
dead
defeated
defiant
delightful
depressed
determined
different
difficult
disgusted
distinct
disturbed
dizzy
doubtful
drab
dull
eager
easy
elated
elegant
embarrassed
enchanting
encouraging
energetic
enthusiastic
envious
evil
excited
expensive
exuberant
fair
faithful
famous
fancy
fantastic
fierce
filthy
fine
foolish
fragile
frail
frantic
friendly
frightened
funny
gentle
gifted
glamorous
gleaming
glorious
good
gorgeous
graceful
grieving
grotesque
grumpy
handsome
happy
healthy
helpful
helpless
hilarious
homeless
homely
horrible
hungry
hurt
ill
important
impossible
inexpensive
innocent
inquisitive
itchy
jealous
jittery
jolly
joyous
kind
lazy
light
lively
lonely
long
lovely
lucky
magnificent
misty
modern
motionless
muddy
mushy
mysterious
nasty
naughty
nervous
nice
nutty
obedient
obnoxious
odd
open
outrageous
outstanding
panicky
perfect
plain
pleasant
poised
poor
powerful
precious
prickly
proud
putrid
puzzled
quaint
real
relieved
repulsive
rich
scary
selfish
shiny
shy
silly
sleepy
smiling
smoggy
sore
sparkling
splendid
spotless
stormy
strange
stupid
successful
super
talented
tame
tasty
tender
tense
terrible
thankful
thoughtful
thoughtless
tired
tough
troubled
ugliest
ugly
uninterested
unsightly
unusual
upset
uptight
vast
victorious
vivacious
vivid
wandering
weary
wicked
wide-eyed
wild
witty
worried
worrisome
wrong
zany
zealous

48
data/colors.txt Normal file
View file

@ -0,0 +1,48 @@
aquamarine
black
blue
brass
brown
burnt-orange
canary
carmine
cerise
cerulean
cobalt
copper
cornflower
denim
eggplant
fuchsia
golden
goldenrod
gray
green
indigo
lavender
magenta
mahogany
maroon
navy
olive
orange
periwinkle
pine
pink
purple
red
red-brick
rose
scarlet
sepia
sienna
silver
tan
teal
turquoise
ultramarine
umber
vermilion
violet
white
yellow

200
data/nouns.txt Normal file
View file

@ -0,0 +1,200 @@
actor
advertisement
afternoon
airport
ambulance
animal
answer
apple
apricot
army
asparagus
australia
balloon
banana
battery
beach
beard
beaver
bed
belgium
boy
branch
breakfast
brother
camera
candle
car
caravan
carpet
cartoon
china
church
crayon
crowd
daughter
death
denmark
desert
diamond
dinner
disease
doctor
dog
dream
dress
easter
egg
eggplant
egypt
elephant
energy
engine
england
evening
eye
family
fern
fish
flag
flower
football
forest
fountain
france
furniture
garage
garden
gas
ghost
giraffe
girl
glass
gold
grass
greece
guitar
hair
hamburger
helicopter
helmet
holiday
honey
horse
hospital
house
hydrogen
ice
insect
insurance
iron
island
jackal
jelly
jeans
jewellery
jordan
juice
kangaroo
king
kitchen
kite
knife
lamp
lawyer
leather
lemon
library
lighter
lion
lizard
lock
london
lunch
machine
magazine
magician
manatee
manchester
market
match
microphone
monkey
morning
motorcycle
nail
napkin
needle
nest
nigeria
night
notebook
ocean
oil
orange
orchid
oxygen
oyster
painting
parrot
peach
pencil
piano
pillow
pizza
planet
plastic
plum
portugal
potato
queen
quill
rain
rainbow
raincoat
refrigerator
restaurant
river
rocket
room
rose
russia
salmon
sand
sandwich
school
scooter
shampoo
shamrock
shoe
soccer
spoon
stone
sugar
sweden
teacher
telephone
television
tent
thailand
tomato
toothbrush
traffic
train
truck
tumbleweed
uganda
umbrella
van
vase
vegetable
vulture
wall
whale
window
wire
xylophone
yacht
yak
zebra
zoo

108
ha-passwords.org Normal file
View file

@ -0,0 +1,108 @@
#+TITLE: Personal Password Generator
#+AUTHOR: Howard X. Abrams
#+EMAIL: howard.abrams@gmail.com
#+DATE: 2021-01-11
#+FILETAGS: :emacs:
A literate programming version for Emacs code to generate and store passwords.
#+BEGIN_SRC emacs-lisp :exports none
;;; ha-passwords.el --- A literate programming version for Emacs code to generate and store passwords. -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2021 Howard X. Abrams
;;
;; Author: Howard X. Abrams <http://gitlab.com/howardabrams>
;; Maintainer: Howard X. Abrams <howard.abrams@gmail.com>
;; Created: January 11, 2021
;;
;; This file is not part of GNU Emacs.
;;
;; *NB:* Do not edit this file. Instead, edit the original literate file at:
;; /Users/howard.abrams/other/hamacs/ha-passwords.org
;; And tangle the file to recreate this one.
;;
;;; Code:
#+END_SRC
* Introduction
Let's assume that I store a bunch of words in data files:
#+BEGIN_SRC emacs-lisp
(defvar ha-passwords-data-files (list (expand-file-name "adjectives.txt"
(expand-file-name "data" hamacs-source-dir))
(expand-file-name "colors.txt"
(expand-file-name "data" hamacs-source-dir))
(expand-file-name "nouns.txt"
(expand-file-name "data" hamacs-source-dir)))
"List of file name containing a data lines for our password generator. Order of these files matter.")
(defvar ha-passwords-data nil
"Contains a list of lists of words that we can choose.")
#+END_SRC
You can see where I'm going with this, can't you? Let's read them into list variables.
#+BEGIN_SRC emacs-lisp
(defun ha-passwords--read-data-file (filename)
(with-temp-buffer
(insert-file-contents filename)
(split-string (buffer-string) "\n" t)))
#+END_SRC
Now we just get three or so words from our list of lists:
#+BEGIN_SRC emacs-lisp
(defun ha-passwords-words ()
(unless ha-passwords-data
(setq ha-passwords-data
(--map (ha-passwords--read-data-file it) ha-passwords-data-files)))
(--map (nth (random (length it)) it) ha-passwords-data))
#+END_SRC
Let's make a password:
#+BEGIN_SRC emacs-lisp
(defun ha-passwords-generate (&optional separator)
(unless separator
(setq separator "-"))
(let* ((choices '("!" "@" "#" "$" "%" "^" "&" "*"))
(choice (random (length choices)))
(number (1+ choice)))
(->> (ha-passwords-words)
(s-join separator)
(s-capitalize)
(s-append (nth choice choices))
(s-append (number-to-string number)))))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun generate-password (&optional separator)
(interactive)
(let ((passphrase (ha-passwords-generate separator)))
(kill-new passphrase)
(message "Random password: %s" passphrase)))
#+END_SRC
* Keybindings
Got make it easy to call:
#+BEGIN_SRC emacs-lisp
(ha-leader "a g" '("generate passwd" . generate-password))
#+END_SRC
* Technical Artifacts :noexport:
This will =provide= a code name, so that we can =require= this.
#+BEGIN_SRC emacs-lisp :exports none
(provide 'ha-passwords)
;;; ha-passwords.el ends here
#+END_SRC
#+DESCRIPTION: A literate programming version for Emacs code to generate and store passwords.
#+PROPERTY: header-args:sh :tangle no
#+PROPERTY: header-args:emacs-lisp :tangle yes
#+PROPERTY: header-args :results none :eval no-export :comments no mkdirp yes
#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil date:nil
#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js