views:

383

answers:

7

When creating a "forgotten password" mechanism, we might want to create a tempory password for the user which is stored using SHA1 (feel free to suggest other C# Cryptography mechanism).

How long should we make the tempory password? Too short, it could be brute forced. Too long and the unnecessary length is redundant since the string is hashed anyway? (Since a 20 character and 50 character string results in a hash of the same length anyway)

Update
Sorry if this was misleading. Sure we can pick a number out of the air, but I was wondering if there was a good mathematical reason to pick 13 rather than 12.

+1  A: 

I generally go with 10 characters. No particular reason for that, just something that I'd guess is above average length for a password chosen by a user.

Just by the fact that it's randomly generated, it'll probably be more secure and more difficult to brute force than anything chosen by your users. People pick stupid passwords such as myspace1, stackoverflow1, 12341234 etc.

Macha
A: 

If the password is in alphanumeric characters you only have about 6 bits of usable data per character and therefore you're wrong that there's no sense making a password longer than 20 characters.

sharptooth
A: 

It seems like you are worried about making the temporary password stronger than the user's password... when in reality, something like a 10-character base-64 (or similar - punctuation etc) is going to be very hard to crack and much stronger than the password the user will generate....

Marc Gravell
A: 

Make it a variable size as well (say 8-12 character) that will make it harder to brute force... if the attacker know you return an X character password all they have to do is try all passwords with N... assuming N is large it'll be impractical, but varying the size of N will at least make it that much harder for them.

TofuBeer
A: 
Zaagmans
A: 

Go for whatever length your site specifies as recommended for the users. When generating a random string of base64 chars, I would sleep safely at night with 8-char password. But of course I'd limit login attempts to once every X second, and temporarily disable account after Y failed tries.

And remember to add a per-user unique salt before hashing, to thwart database-based attacks.

snemarch
+1  A: 

I think this is good advice regarding temp passwords:

http://stackoverflow.com/questions/549/the-definitive-guide-to-website-authentication-beta/477583#477583

It talks about avoiding generating them in favour of getting to the real action the user wants.

meandmycode
+1 didn't know there was an SO wiki for this.
Dead account