I would like to generate a random password of a defined length which can easily be typed in with a standard keyboard.
As a start I tried the following:
SeedRandom["pass"];
StringJoin[RandomChoice[CharacterRange[33, 126], 10]
(* "=IP@7mbYcB" *)
Do you know other solutions?
Answer
A shorter formulation equivalent to your own code is:
FromCharacterCode @ RandomInteger[{33, 126}, 10]
"+(pCT4W#;T"
However quite a few places only accept alphanumeric passwords, and not all keyboards have the same easily accessible character sets. If we assume that your given example is sufficiently secure you need 94^10 ~= 5*10^19 unique passwords. This is easily accomplished by adding a single alphanumeric character as 62^11 ~= 5*10^19. Therefore I propose:
rnd =
FromCharacterCode @
RandomChoice[Join @@ Range[{48, 97, 65}, {57, 122, 90}], #] &;
rnd[11]
"liLC2RoA3cR"
Or five passwords at once:
rnd[{5, 11}]
{"suPwm0c7FxS", "CV3khXaowWS", "Lac9z1IVCwc", "gptfkp2GMwH", "HDhRuFPLxte"}
Comments
Post a Comment