14
1
I have so many secrets and nowhere to keep them!
The goal is simple: write a program that lets you save a string and have it be protected by a password.
The program will take an alias, password and (optional) secret as parameters.
If this is the first time the program is called with a given alias, then it will store/remember the secret, and output whatever you want.
If the program is called with an alias that has been used before, then it will output the secret for that alias iff the password is the same as the first time the program was run with that alias.
Other cases
If its the first time being called with a certain alias and no secret is given - store nothing.
If the program is called with an alias that has been used, and the password is incorrect - return any kind of error or nothing at all.
If the program is called with an alias that has been used, the password is correct and a new secret is supplied - output the old secret and replace it with the new one so that next time only the new secret is output.
If the program is called with an alias that has been used, the password is correct and no new secret is supplied - output the old secret and make sure it doesn't get replaced.
Note: These secrets/passwords do not need to be stored securely
Also note: any alphanumeric input for aliases passwords and secrets should be accepted
Standard rules apply, good luck!
What kind of storage may we use? Anything? – Adám – 2019-05-16T21:00:49.420
May we limit the valid aliases to say lowercase alphabetical words? – Adám – 2019-05-16T21:01:18.520
1Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input – Quinn – 2019-05-16T21:05:15.593
Updated question to specify – Quinn – 2019-05-16T21:08:14.427
1May we use a function rather than a full program? – Arnauld – 2019-05-16T21:16:21.347
1@Arnauld I'll allow it – Quinn – 2019-05-16T21:19:38.430
1May we assume the password and secret are not the empty string? – xnor – 2019-05-17T02:14:47.707
1May we output a null answer (like 0 or None) in any situation where we don't output the secret? – xnor – 2019-05-17T02:37:16.607
1@xnor I will say yes to both those questions – Quinn – 2019-05-17T02:47:18.733
May we output different falsy values (like
false
andundefined
) when there's no secret to output? – Arnauld – 2019-05-20T21:05:51.997@Arnauld yes you may – Quinn – 2019-05-20T21:13:37.907