Hi gents, sorry for the late reply!
@Terry_Stagg , I do have some code I’ve used recently for my new doc (Encryption in Coda: Can you keep a secret?)
It’s really efficient, and will generate a ton of passwords quickly, however they may not necessarily meet your requirements every time so you’ll need to built in some way to validate the output before acceptance (I’ve got a second solution further down which will meet your requirements)
Split("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-=+", "")
.RandomSample(12, False(), True())
.Join("")
How this works…
- Passing a blank string ("") to the Split() formula takes the string of characters and breaks them up into an array of individual characters.
- Next we pass that array to RandomSample() which is a formula which picks a set number of random items out of whatever array you pass it. In this case we request 12 items.
- Finally, we Join() the randomly picked characters together. The empty string means that the characters are glued together without any delimiter.
The False() and True() arguments for RandomSample() are options for withReplacement and updateContinuously (respectively).
withReplacement set to false means that characters are not allowed to potentially repeat in the random sample. If you’re ok with having a letter potentially repeat in the output, set this to true.
updateContinuously will generate new random samples whenever the doc loads, so you’re more likely to get unique results. Note however, you’ll need to STORE the output, otherwise your users passwords will change each time the doc is loaded!
If you wanted to generate these using a button, then the formula for the button would be something like:
thisRow.ModifyRows(
thisRow.Password,
Split("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-=+_", "")
.RandomSample(12, False, True)
.Join("")
)
If you wanted to ENSURE upper/lower/special in ALL outputs, a solution could be to repeat the above code 3 times with separate strings passed for the three character categories, then join the whole bunch together. I’ve built a doc to show you both solutions.
Hope that helps!