(phixonline)-->
--with javascript_semantics -- not quite yet:
without js -- (VALUECHANGED_CB not yet triggering)
constant az = "abcdefghijklmnopqrstuvwxyz",
AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
O9 = "1234567890",
OT = "!\"#$%&'()*+,-./:;<=>?@[]^_{|}~"
function password(integer len, integer n, sequence exclude="Il1O05S2Z")
sequence res = {},
S4 = apply(true,filter,{{az,AZ,O9,OT},{"out"},{exclude}})
string pw = repeat(' ',len)
for i=1 to n do
sequence sel = shuffle({1,2,3,4}&sq_rand(repeat(4,len-4)))
for c=1 to len do
string S4c = S4[sel[c]]
pw[c] = S4c[rand(length(S4c))]
end for
res = append(res,pw)
end for
return res
end function
include pGUI.e
Ihandle lenl, leng, numl, numb, res, dlg
function valuechanged_cb(Ihandle /*leng|numb*/)
integer l = IupGetInt(leng,"VALUE"),
n = IupGetInt(numb,"VALUE")
string s = join(password(l,n),"\n")
s = substitute(s,"&","&&") -- (on p2js??)
IupSetStrAttribute(res,"TITLE",s)
IupSetAttribute(dlg,"SIZE",NULL)
IupRefresh(dlg)
return IUP_DEFAULT
end function
procedure main()
IupOpen()
lenl = IupLabel("length(4..99)")
leng = IupText("SPIN=YES,SPINMIN=4,SPINMAX=99")
numl = IupLabel("number(1..99)")
numb = IupText("SPIN=YES,SPINMIN=1,SPINMAX=99")
res = IupLabel("","FONTFACE=Courier")
IupSetCallback({leng,numb},"VALUECHANGED_CB", Icallback("valuechanged_cb"))
dlg = IupDialog(IupVbox({IupHbox({lenl,leng,numl,numb},"GAP=10,NORMALIZESIZE=VERTICAL"),
IupHbox({res})},"MARGIN=5x5"),
`TITLE="Password Generator"`)
IupShow(dlg)
if platform()!=JS then
IupMainLoop()
IupClose()
end if
end procedure
main()