hpg 0.5 → 0.6
raw patch · 4 files changed
+149/−71 lines, 4 files
Files
README.md view
@@ -7,6 +7,7 @@ # SYNOPSIS **hpg**+\[**-N**] \[**-lnsu**] \[**-x** *length*] @@ -14,29 +15,34 @@ The **hpg**-utility creates passwords of different sizes, between 1 and 2^16 signs. Please note that a+utility creates passwords of different sizes, between 1 and 2^16 characters. Please note that a lenght of <8 is not very secure and should be avoided. That is why the default value is 16-if the command is called without any options. The default entropy contains \[a-zA-Z0-9].+if the command is called without any options. The default entropy contains lower and upper+case letters and numbers. **-l** -> Use lower case.+> Enables lower case letters. +**-N**++> Disables the printing of the trailing newline character.+ **-n** -> Use numbers.+> Enables numbers. **-s** -> Use symbols.+> Enables special characters. **-u** -> Use upper case.+> Enables upper case letters. -**-x**+**-x** *length* -> Use another length, as the default one.+> Selects the length of the password. # EXIT STATUS @@ -48,10 +54,8 @@ $ hpg -lnsu -x 32 -# COPYRIGHT+# AUTHORS -Copyright © 2017 Fritjof Bornebusch -This is free software; see the file COPYING for copying conditions. There is NO-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.+Fritjof Bornebusch <[fritjof@alokat.org](mailto:fritjof@alokat.org)> OpenBSD 6.1 - March 21, 2017
+ hpg.1 view
@@ -0,0 +1,52 @@+.\"Copyright (c) 2017 Fritjof Bornebusch <fritjof@alokat.org>+.\"+.\"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 $Mdocdate: March 21 2017 $+.Dt HPG 1+.Os+.Sh NAME+.Nm hpg+.Nd simple password generator+.Sh SYNOPSIS+.Nm hpg+.Op Fl N+.Op Fl lnsu+.Op Fl x Ar length+.Sh DESCRIPTION+The+.Nm+utility creates passwords of different sizes, between 1 and 2^16 characters. Please note that a+lenght of <8 is not very secure and should be avoided. That is why the default value is 16+if the command is called without any options. The default entropy contains lower and upper+case letters and numbers.+.Bl -tag -width Dsssigfile+.It Fl l+Enables lower case letters.+.It Fl N+Disables the printing of the trailing newline character.+.It Fl n+Enables numbers.+.It Fl s+Enables special characters.+.It Fl u+Enables upper case letters.+.It Fl x Ar length+Selects the length of the password.+.Sh EXIT STATUS+.Ex -std hpg+.Sh EXAMPLES+Create a new random password:+.Dl $ hpg -lnsu -x 32+.Sh AUTHORS+.An -nosplit+.An Fritjof Bornebusch Aq Mt fritjof@alokat.org
hpg.cabal view
@@ -1,22 +1,23 @@--- Initial hpg.cabal generated by cabal init. For further documentation, --- see http://haskell.org/cabal/users-guide/- name: hpg-version: 0.5-synopsis: password generator-description: the haskell password generator.+version: 0.6+synopsis: a simple password generator+description: hpg is a free, open source password generator. It's design+ is pretty simple and it generates random passwords between+ 1 and 2^16 characters.+ homepage: https://darcs.alokat.org/hpg license: ISC license-file: LICENSE author: Fritjof Bornebusch maintainer: fritjof@alokat.org-category: System+category: Security stability: Experimental build-type: Simple cabal-version: >=1.16 extra-source-files: README.md+ hpg.1 source-repository head type: darcs
hpg.hs view
@@ -16,19 +16,19 @@ {-# LANGUAGE CPP #-} -import System.Console.GetOpt-import System.Environment (getArgs)-import System.Exit (exitFailure, exitSuccess)-import System.IO (stdout, stderr, hFlush, hPutStr)+module Main ( main ) where++import System.Console.GetOpt ( ArgDescr(ReqArg, NoArg), ArgOrder(RequireOrder),+ getOpt, OptDescr(Option) )+import System.Environment ( getArgs )+import System.Exit ( exitFailure, exitSuccess )+import System.IO ( hPutStr, stderr, stdout )+ #ifdef openbsd_HOST_OS-import System.OpenBSD.Process (pledge)+import System.OpenBSD.Process ( pledge ) #endif -import System.Random (randomRIO) -exit_with_message :: String -> IO ()-exit_with_message msg = do- hPutStr stderr (msg ++ "\n")- exitFailure+import System.Random ( randomRIO ) upperCaseLettersList :: [Char] upperCaseLettersList = ['A'..'Z']@@ -42,33 +42,36 @@ specialCharactersList :: [Char] specialCharactersList = ['!'..'/'] ++ [':'..'@'] ++ ['['..'_'] ++ ['{'..'~'] -data Options = Options { optUpperCaseFlag :: Bool- ,optLowerCaseFlag :: Bool- ,optNumbersFlag :: Bool- ,optSpecialCharactersFlag :: Bool- ,optLengthValue :: Int+data Options = Options { optLowerCaseFlag :: Bool+ , optNoNewLineFlag :: Bool+ , optNumbersFlag :: Bool+ , optSpecialCharactersFlag :: Bool+ , optUpperCaseFlag :: Bool+ , optLengthValue :: Int } startOptions :: Options-startOptions = Options { optUpperCaseFlag = False- , optLowerCaseFlag = False - , optNumbersFlag = False+startOptions = Options { optLowerCaseFlag = False+ , optNoNewLineFlag = False+ , optNumbersFlag = False , optSpecialCharactersFlag = False+ , optUpperCaseFlag = False , optLengthValue = 16 } options :: [ OptDescr (Options -> IO Options) ] options =- [ Option "u" []- (NoArg- (\opt -> return opt { optUpperCaseFlag = True }))- "upper case letters"- - , Option "l" []+ [+ Option "l" [] (NoArg (\opt -> return opt { optLowerCaseFlag = True })) "lower case letters"- + + , Option "N" []+ (NoArg+ (\opt -> return opt { optNoNewLineFlag = True}))+ "no newline"+ , Option "n" [] (NoArg (\opt -> return opt { optNumbersFlag = True }))@@ -77,7 +80,12 @@ , Option "s" [] (NoArg (\opt -> return opt { optSpecialCharactersFlag = True }))- "special signs"+ "special characters"++ , Option "u" [] + (NoArg + (\opt -> return opt { optUpperCaseFlag = True }))+ "upper case letters" , Option "x" [] (ReqArg@@ -86,12 +94,17 @@ "password length" ] +exitWithMessage :: String -> IO ()+exitWithMessage msg = do+ hPutStr stderr (msg ++ "\n")+ exitFailure+ parse :: [String] -> IO ([Options -> IO Options], [String]) parse args = case getOpt RequireOrder options args of (actions, nonOptions,[]) -> return (actions, nonOptions) (_,_,errors) -> ioError (userError (concat errors ++ header)) - where header = "usage: hpg [-ulns]\n" ++ + where header = "usage: hpg [-lnsu]\n" ++ " [-x number]" randomList :: Int -> [Char] -> IO([Int])@@ -102,49 +115,57 @@ rs <- randomList (n-1) list return (r:rs) -create_password :: Int -> [Bool] -> IO [Char]-create_password lengthValue flags = do- let l = create_signs [upperCaseLettersList,- lowerCaseLettersList,- numbersList,- specialCharactersList] flags+createPassword :: Int -> [Bool] -> IO [Char]+createPassword lengthValue flags = do+ let l = createList [lowerCaseLettersList,+ numbersList,+ specialCharactersList,+ upperCaseLettersList] flags rl <- randomList lengthValue l return [l !! i | i <- rl] -add_signs :: [Char] -> ([Char], Bool) -> [Char] -add_signs list (l, True) = list ++ l-add_signs list (_, False) = list+addToList :: [Char] -> ([Char], Bool) -> [Char] +addToList list (l, True) = list ++ l+addToList list (_, False) = list -create_signs :: [[Char]] -> [Bool] -> [Char]-create_signs signs [False, False, False, False] = do- -- default values are upper case and lower case letters- create_signs signs [True, True, True, False]+createList :: [[Char]] -> [Bool] -> [Char]+createList characters [False, False, False, False] = do+ -- default values are lower case, numbers and+ -- upper case letters+ createList characters [True, True, False, True] -create_signs signs flags = do- let z = zip signs flags- foldl (\x y -> add_signs x y) [] z+createList characters flags = do+ let z = zip characters flags+ foldl (\x y -> addToList x y) [] z main :: IO () main = do+ #ifdef openbsd_HOST_OS pledge (Just "stdio") Nothing #endif+ (actions, _nonOptions) <- getArgs >>= parse opts <- foldl (>>=) (return startOptions) actions- let Options { optUpperCaseFlag = upperCase- , optLowerCaseFlag = lowerCase+ let Options { optLowerCaseFlag = lowerCase+ , optNoNewLineFlag = noNewLine , optNumbersFlag = numbers , optSpecialCharactersFlag = specialCharacters+ , optUpperCaseFlag = upperCase , optLengthValue = lengthValue } = opts if lengthValue > 2^(16::Int)- then exit_with_message "password too long"+ then exitWithMessage "password too long" else do- pwd <- create_password lengthValue [upperCase,- lowerCase,+ pwd <- createPassword lengthValue [lowerCase, numbers,- specialCharacters]- hPutStr stdout (pwd ++ "\n")- hFlush stdout- exitSuccess+ specialCharacters,+ upperCase]+ + hPutStr stdout pwd+ case noNewLine of+ False -> hPutStr stdout "\n"+ _ -> return ()++ exitSuccess