[erlang-questions] Password generator in Erlang

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Aug 16 18:11:56 CEST 2012


On Thu, Aug 16, 2012 at 04:53:01PM +0200, Artem Teslenko wrote:
> One more way to generate the passwords:
> 
> random:seed(now()).
> base64:encode_to_string(crypto:rand_bytes(16)).
> 
> "EbvUy9ZHTqoAOvMSZ53X5A=="
> 
> After that just remove the unnecessary characters.

That is almost the same as my command line suggestion but in all erlang.
Very nice!

If you choose the number of bytes as a multiple of 6 you will not get
any trailing `=' and translate any generated Base64 characters `+'
and `/' (at least `/' is not popular by some password checkers)
into something else, see my example of using `.' and `,' below,
then it is the same suggestion.
  [case X of $+ -> $.; $/ -> $,; X -> X end
   || X <- base64:encode_to_string(crypto:rand_bytes(12))]
->
  "dSdCpgl.wuGaMzsr"

/ Raimo

> 
> On Thu, 16 Aug 2012, Raimo Niskanen wrote:
> 
> > On Wed, Aug 15, 2012 at 11:42:06AM +1200, Richard O'Keefe wrote:
> > > 
> > > On 15/08/2012, at 4:44 AM, Loïc Hoguin wrote:
> > > 
> > > > On 08/14/2012 06:09 PM, Zabrane Mickael wrote:
> > > >> 
> > > >> On Aug 14, 2012, at 5:40 PM, Loïc Hoguin wrote:
> > > >> 
> > > >>> os:cmd("pwgen | cut -c 1-8").
> > > >> 
> > > >> a portable one ;-)
> > > > 
> > > > I believe pwgen and cut are available on all of win/linux/bsd/osx.
> > > 
> > > m% man pwgen
> > > No manual entry for pwgen
> > > 
> > > Mac OS X 10.6.8.
> > > 
> > > v% man pwgen
> > > No manual entry for pwgen
> > > 
> > > Linux 2.6.31.5-127.fc12.x86_64
> > > 
> > > f% man pwgen
> > > No manual entry for pwgen.
> > > 
> > > Solaris.
> > > 
> > > Available?  May be, I don't know.
> > > Installed?  NO.
> > 
> > And the same applies to Ubuntu, FreeBSD and OpenBSD...
> > 
> > This might be more portable:
> >   openssl rand -base64 6 | tr +/ .,
> > 
> > > 
> > > 
> > > _______________________________________________
> > > erlang-questions mailing list
> > > erlang-questions@REDACTED
> > > http://erlang.org/mailman/listinfo/erlang-questions
> > 
> > -- 
> > 
> > / Raimo Niskanen, Erlang/OTP, Ericsson AB
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list