Is UUID.randomUUID() suitable for use as a one-time password?

前端 未结 7 1270
夕颜
夕颜 2020-12-25 11:49

As previous discussed, confirmation emails should have a unique, (practically) un-guessable code--essentially a one-time password--in the confirmation link.

The UUI

相关标签:
7条回答
  • 2020-12-25 12:40

    No. According to the UUID spec:

    Do not assume that UUIDs are hard to guess; they should not be used as security capabilities (identifiers whose mere possession grants access), for example. A predictable random number source will exacerbate the situation.

    Also, UUIDs only have 16 possible characters (0 through F). You can generate a much more compact and explicitly secure random password using SecureRandom (thanks to @erickson).

    import java.security.SecureRandom;
    import java.math.BigInteger;
    
    public final class PasswordGenerator {
        private SecureRandom random = new SecureRandom();
    
        public String nextPassword() {
            return new BigInteger(130, random).toString(32);
        }
    }
    
    0 讨论(0)
提交回复
热议问题