PasswordGenerator icon indicating copy to clipboard operation
PasswordGenerator copied to clipboard

Should throw instead of returning "Try again" when a valid password cannot be found

Open rasitha1 opened this issue 5 years ago • 3 comments

Can the call to .Next() throw instead of returning a password called "Try again" when a valid password could not be generated in maximumAttempts?

I think it's a big risk to return a string like that as the calling application has no way to know what was returned is not a valid password.

A dedicated exception type would be a bonus.

                password = PasswordIsValid(Settings, password) ? password : "Try again";

Source

rasitha1 avatar Feb 05 '20 23:02 rasitha1

Indeed, you either throw exception or use TryXXX pattern

bool TryGenerate(out string password)

clement128 avatar Jul 20 '20 03:07 clement128

@clement128 good idea, but I decided to go with a dedicated exception type. Mainly because I did not want to break backwards compatibility with this project in my fork.

saciervo avatar Apr 14 '21 23:04 saciervo

I actually don't see why you could not guarantee password generation with every call. you might need to tweak the algorithm but I really cannot fathom any reason why it would not be possible... :/

Ib01 avatar Jun 30 '21 05:06 Ib01