|
Post by Josh on May 5, 2017 19:03:58 GMT
Password Generation
You must write a program that outputs a random password of a character length between 12 and 24.The generated password must include all of the following:- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character (*!"; etc)
Feel free to golf the code. If you are doing so, please post the length of your solution along with the language you wrote it in. Otherwise, just ensure that you post the language your solution is written in.
Good luck!
|
|
lae
Active Member
Veteran
Posts: 27
ROBLOX Username: LaeMVP
|
Post by lae on May 5, 2017 19:26:46 GMT
Lua, 118 characters
math.randomseed(tick())warn(string.char(math.random(65,90),math.random(97,122),math.random(47,57),math.random(36,46)))
|
|
|
Post by goulstem on May 5, 2017 20:02:10 GMT
Could definitely prolly go shorter but this method came to mind first.
Lua, 335 chars
f,t=false,true;l,u,n,a,m,s,p={97,122},{65,90,f},{48,57,f},{f,{33,47},{58,64},{91,96},{123,126}},math.random,string.char,"";
for i = 1,m(12,24) do if not u[3]then u[3]=t;p=p..s(m(u[1],u[2]))elseif not n[3]then n[3]=t;p=p..s(m(n[1],n[2]))elseif not a[1] then a[1]=t;b=a[m(2,5)]p=p..s(m(b[1],b[2]))else p=p..s(m(l[1],l[2]))end;end
print(p);
|
|
|
Post by Josh on May 5, 2017 20:08:54 GMT
Looks good goulstem! lae, thanks for the contribution - the program does have to generate a password between the length of 12 and 24 though.
|
|
|
Post by Bit on May 5, 2017 20:22:36 GMT
|
|
Purely
New Member
Posts: 16
ROBLOX Username: PurelyMystic
|
Post by Purely on May 5, 2017 20:25:52 GMT
Lua
local Chars = math.random(12,24) local SpecialChars = {"#","%","*","("}; local Data = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; local Password = ""; for i=1, Chars do Password = Password..Data[math.random(1,#Data)]..SpecialChars[math.random(1,#SpecialChars)]..math.random(1,9)..Data[math.random(1,#Data)]:upper() end
print(Password:sub(1,Chars))
|
|
|
Post by Bit on May 5, 2017 20:27:52 GMT
|
|
|
Post by goulstem on May 5, 2017 20:40:05 GMT
Alright second try
Lua, 238 chars
l,u,n,a,m,s={97,122},{65,90},{48,57},{{33,47},{58,64},{91,96},{123,126}},math.random,string.char;u=s(m(u[1],u[2]))n=s(m(n[1],n[2]))A=a[m(1,4)]S=s(m(A[1],A[2]))L=("l"):rep(m(9,21))p=u..n..S;for i = 1,#L do p=p..s(m(l[1],l[2]))end;print(p);
|
|
|
Post by Josh on May 5, 2017 20:49:13 GMT
Great solution goulstem! If you're trying to golf it down to as short as possible, make sure that you remove all unnecessary spaces and get rid of the semi-colon at the end
|
|
|
Post by Josh on May 5, 2017 21:33:55 GMT
|
|
Purely
New Member
Posts: 16
ROBLOX Username: PurelyMystic
|
Post by Purely on May 5, 2017 21:34:50 GMT
211 Chars
local C=math.random(12,24);local Sp={"$","#","*"};local Pa="";for i=1,C do Pa=Pa..string.char(math.random(65, 90)):lower()..string.char(math.random(65, 90)):upper()..Sp[math.random(1,#Sp)];end print(Pa:sub(1,C))
|
|
|
Post by goulstem on May 5, 2017 21:34:57 GMT
Nice, Purely :3 You could even go shorter w/ smaller variables
|
|
Purely
New Member
Posts: 16
ROBLOX Username: PurelyMystic
|
Post by Purely on May 5, 2017 21:39:27 GMT
Made a oopsie Here's the fixed version.
s={"#","%","^"};P="";for i=1,24 do P=P..string.char(math.random(65,90)):lower()..string.char(math.random(65,90))..s[math.random(1,#s)];end print(P:sub(1,15))
|
|
|
Post by Bit on May 5, 2017 21:40:40 GMT
EVEN SHORTAHHHH!
|
|
Purely
New Member
Posts: 16
ROBLOX Username: PurelyMystic
|
Post by Purely on May 5, 2017 21:44:54 GMT
Here you go! 116 Chars! I don't think I can go any lower lol...
p="";for i=1,25 do p=p..string.char(math.random(65,90))..string.char(math.random(97,99)).."#";end print(p:sub(1,15))
|
|