Page 1 of 1
Speakable Pass generator
Posted: Tue Aug 17, 2010 8:15 pm
by p4tr1ck
I am making a speakable password generator for school. I can't seem to get this right. Instead of a mixture of vowels and consonants, it simply creates vowels and spaces.
Code: Select all
on mouseUp
local lResult
local i
local lVowels
local lConts
local sType
put 1 into i;
put "" into lResult
put "aeiou" into lVowels
put "bcdfghjklmnprstwyz" into lConts
put 0 into sType
repeat 40 times
local lRandomCharNum
local lRandomChar
if sType is 1 then
put randomInRange(1,5) into lRandomCharNum
put char lRandomCharNum of lVowels into lRandomChar
end if
if sType is 0 then
put randomInRange(1,18) into lRandomCharNum
put char lRandomCharNum of lVowels into lRandomChar
end if
put lResult && lRandomChar into lResult
if sType is 1 then put 0 into sType;
else put 1 into sType;
put lResult into field "output"
if i is the thumbPos of scrollbar "pLength" then exit repeat;
add 1 to i
end repeat
end mouseUp
Thanks for your help.
Re: Speakable Pass generator
Posted: Tue Aug 17, 2010 9:32 pm
by bn
patrick
I changed some of your code. The main problem was that you used lVowels twice instead of lConts and lVowels. In Rev if you append with double ampersand (&&) you effectively insert a space.
I commented the other changes I made, have a look.
Code: Select all
on mouseUp
local lResult
local i
local lVowels
local lConts
local sType
put 1 into i;
put "" into lResult
put "aeiou" into lVowels
put "bcdfghjklmnprstwyz" into lConts
put 0 into sType
put the thumbPos of scrollbar "pLength" into tLengthPassword -- changed this
repeat tLengthPassword -- changed this
local lRandomCharNum
local lRandomChar
if sType is 1 then
put randomInRange(1,5) into lRandomCharNum
put char lRandomCharNum of lVowels into lRandomChar
end if
if sType is 0 then
put randomInRange(1,18) into lRandomCharNum
put char lRandomCharNum of lConts into lRandomChar -- changed this, was lVowels
end if
put lRandomChar after lResult -- changed this
if sType is 1 then put 0 into sType;
else put 1 into sType;
-- put lResult into field "output" -- blocked this, it moved out ot the repeat loop
-- if i is the thumbPos of scrollbar "pLength" then exit repeat; -- blocked this
-- add 1 to i --blocked this
end repeat
put lResult into field "output"
end mouseUp
function randomInRange lowerLimit,upperLimit
return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomInRange
it works in my limited testing.
For a random vowel or consonant in your list you could just as well say: put any char of lVowels after lResult, for consonants likewise. Look up "any"
regards
Bernd
Re: Speakable Pass generator
Posted: Tue Aug 17, 2010 10:29 pm
by bn
patrick,
just to make the code a bit shorter here is a version that does what you want
Code: Select all
on mouseUp
put the thumbPosition of scrollbar "pLength" into tPasswordLength
put "bcdfghjklmnprstwyz" into lConts
put "aeiou" into lVowels
put "" into tResult
repeat tPasswordLength
if tResult = "" or last char of tResult is in lVowels then
put any char of lConts after tResult
else
put any char of lVowels after tResult
end if
end repeat
put tResult into field "output"
end mouseUp
regards
Bernd
Re: Speakable Pass generator
Posted: Sat Aug 21, 2010 12:39 pm
by Mark
Hi,
Here's a function that allows for double consonants while the password is still speakable.
Code: Select all
function speakablePassword theLength
put "bcdfghjklmnprstwyz" into myConsonants
put "aeiou" into myVowels
put "" into myPass
repeat theLength
if char -1 of myPass is in myConsonants then
if char -2 of myPass is in myConsonants or \
length(myPass) = 9 then
put any char of myVowels after myPass
else
if any item of "true,false" then
put any char of myVowels after myPass
else
put any char of myConsonants after myPass
end if
end if
else
put any char of myConsonants after myPass
end if
end repeat
return myPass
end speakablePassword
Enjoy,
Mark
Re: Speakable Pass generator
Posted: Sat Sep 04, 2010 9:06 am
by Mark
Here's a stack, which generates even slightly better speakable passwords.