Pin Generation

前端 未结 11 957
走了就别回头了
走了就别回头了 2021-01-31 05:26

I am looking to develop a system in which i need to assign every user a unique pin code for security. The user will only enter this pin code as a means of identifying himself. T

11条回答
  •  误落风尘
    2021-01-31 06:14

    Should i generate this code via some sort of algorithm?

    No. It will be predictable.

    Or should i randomly generate it?

    Yes. Use a cryptographic random generator, or let the user pick their own PIN.

    In theory 4 digits will be plenty as ATM card issuers manage to support a very large community with just that (and obviously, they can't be and do not need to be unique). However in that case you should limit the number of attempts at entering the PIN and lock them out after that many attempts as the banks do. And you should also get the user to supply a user ID (in the ATM case, that's effectively on the card).

    If you don't want to limit them in that way, it may be best to ditch the PIN idea and use a standard password (which is essentially what your PIN is, just with a very short length and limited character set). If you absolutely must restrict it to numerics (because you have a PIN pad or something) then consider making 4 a (configurable) minimum length rather than the fixed length.

    You shouldn't store the PIN in clear anywhere (e.g. salt and hash it like a password), however given the short length and limited char set it is always going to be vulnerable to a brute force search, given an easy way to verify it.

    There are various other schemes that can be used as well, if you can tell us more about your requirements (is this a web app? embedded system? etc).

提交回复
热议问题