Search code examples
sqlpasswordssqldatatypes

Best sql type for a Credit card password


I'm working on a credit card project that interacts with people's money and so I need to store a password. This password should not contain any character but numbers [0-9] and it should be a 4-digits always.

I don't know what sql data type to use for this password.

Here are some situations I have in mind:
A. If I chose int I should check the password to be between 1000 and 9999
B. if I chose Char(4) then I should check the password to be only numbers (and not characters)
C. if I chose Decimal(4,0) then I'm sure that it's below 10000 but I still need to check it for being greater than 999

What do you suggest for such a password and why?


Solution

  • You should store the pin code as Char(4). If you choose 'int' you will have problem by some pin codes like '0042' because it will store without zero. If you chose Char(4) you can validate the the pin code by this method Char.IsNumber(ch).