diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be303db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.fasl diff --git a/README.md b/README.md index 53943d1..aee44aa 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,21 @@ # pwg -### _Your Name _ -This is a project to do ... something. +Generate random passwords -## License +To run: +$> pwg +will return a random password with default length of 8 -Specify license here +$> pwg [positive integer] +will return a random password with length of [positive integer] given as a parameter + +To create a standalone executable: + +$> sbcl + +* (ql:quickload :pwg) + +* (in-package :pwg) + +* (sb-ext:save-lisp-and-die "pwg" :toplevel #'main :executable t :compression 9) diff --git a/pwg.fasl b/pwg.fasl deleted file mode 100644 index 8acbffc..0000000 --- a/pwg.fasl +++ /dev/null Binary files differ diff --git a/pwg.lisp b/pwg.lisp index 8e1f11e..5697f21 100644 --- a/pwg.lisp +++ b/pwg.lisp @@ -2,19 +2,30 @@ (in-package #:pwg) -(defvar +characters+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&()_=") +(defparameter +characters+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&()_=") -(defvar +length-characters+ (length +characters+)) +(defparameter +length-characters+ (length +characters+)) + +(defparameter +default-length+ 8) (defun generate-password (pwd-length) "Generate a password of length PWD-LENGTH" - (let ((password (make-array 0 :element-type 'character :fill-pointer 0 :adjustable t))) + (let ((password (list)) + (index 0)) (dotimes (i pwd-length) - (vector-push-extend (char +characters+ (random (1- +length-characters+))) password)) - password - (format t password))) + (setf index (random +length-characters+ (make-random-state t))) + (setf password (concatenate 'string password (subseq +characters+ index (1+ index)))) ) + (format t "~a~%" password))) + +(defun show-usage () + (format t "USAGE:~% pwg : Generates a password with default length of ~a ~% pwg n : Where n is a positive integer greater than or equal to ~a~%" +default-length+ +default-length+)) ;;;; https://stackoverflow.com/questions/5009853/how-to-pass-arguments-to-saved-sbcl-core (defun main () - (let ((argv sb-ext:*posix-argv*)) - )) + (let* ((argv (uiop:command-line-arguments)) + (first-arg (if (and (not (null argv)) (parse-integer (first argv) :junk-allowed t)) + (parse-integer (first argv)) + nil))) + (cond ((null argv) (generate-password +default-length+)) + ((and (numberp first-arg) (>= first-arg +default-length+)) (generate-password first-arg)) + (t (show-usage)))))