Commit Diff


commit - 4602d277c689ba05915898b55c6f2985045aa6b5
commit + ee89c9f13862af202295b29031eb7cb52a102e88
blob - 570b1e46193b9020335b4d6cb18a67c66a897f77
blob + 3977812b16b32a0a24dcf5763fb0227709d8663a
--- Makefile
+++ Makefile
@@ -1,7 +1,7 @@
 VERSION=	0.2
 DISTNAME=	plass-${VERSION}
-PROGS=		plass totp
-MANS=		plass.1 totp.1
+PROGS=		plass pwg totp
+MANS=		plass.1 pwg.1 totp.1
 EXTRA=		README.md Makefile totp.c
 
 CFLAGS=		-Wall -Wextra
blob - /dev/null
blob + 1ef1fd965f951d1db60fed5ee5b5be13034cbc4a (mode 755)
--- /dev/null
+++ pwg
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# Copyright (c) 2022 Omar Polo <op@omarpolo.com>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+me=$(basename "$0")
+
+usage() {
+	echo "usage: $me [-an] [-w wordlist] [len]" >&2
+	exit 1
+}
+
+wordlist=
+chars="[:print:]"
+len=32
+
+while getopts anw: ch; do
+	case $ch in
+	a)	chars="[:alnum:]" ;;
+	n)	chars="[:digit:]" ;;
+	w)	wordlist="$OPTARG"; len=6 ;;
+	?)	usage ;;
+	esac
+done
+shift $(($OPTIND - 1))
+
+[ $# -gt 1 ] && usage
+[ $# -eq 1 ] && len="$1"
+
+if [ -n "$wordlist" ]; then
+	passphrase=$(sort -R "$wordlist" | head -n "$len")
+	[ -n "$passphrase" ] && echo $passphrase
+else
+	export LC_ALL=C
+	tr -cd "$chars" </dev/urandom | dd bs=1 count="$len" 2>/dev/null && \
+		echo
+fi
blob - /dev/null
blob + e5b25d87be3ce24bb9aaef9b8d1907a207ec123f (mode 644)
--- /dev/null
+++ pwg.1
@@ -0,0 +1,68 @@
+.\" Copyright (c) 2021, 2022 Omar Polo <op@omarpolo.com>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.Dd December 2, 2022
+.Dt PWG 1
+.Os
+.Sh NAME
+.Nm pwg
+.Nd password generator
+.Sh SYNOPSIS
+.Nm
+.Op Fl an
+.Op Fl w Ar wordlist
+.Op Ar length
+.Sh DESCRIPTION
+.Nm
+is a simple password generator.
+It outputs a random string of characters or a diceware-style pass
+phrase.
+The random properties are the ones provided by the operating system'
+.Pa /dev/urandom
+and
+.Xr sort 1
+.Fl R .
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl a
+use only alphanumeric characters.
+.It Fl n
+use only numbers.
+.It Fl w Ar wordlist
+generate a passphrase using words from the
+.Ar wordlist
+file.
+.El
+.Pp
+If no
+.Ar length
+is given, an appropriate number is used.
+.Sh EXIT STATUS
+.Ex -std
+.Sh EXAMPLES
+Generate a passphrase using the EFF
+.Dq large
+wordlist:
+.Bd -literal
+$ ftp \-o\- https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt \e
+	| awk '{print $2}' >~/wordlist
+$ pwg \-w ~/wordlist
+elm retouch disclose snaking pregame bonfire
+.Ed
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+utility was written by
+.An Omar Polo Aq Mt op@omarpolo.com .