Unique text box in MySQL and php

I created salt using; md5 (RAND (0,10000000)); (maybe the best way?)

It seems that it is not possible to create a text field in MYSQL. So, how can I check if the salt has already been used for the previous user?

Or do I need to generate a salt based on the current date / time? since it is not possible for 2 users to register exactly at the same time correctly?

+5
source share
6 answers

For salt, uniqueness is more important than length and predictability. You assume the attacker has salt.

(UUID), , php uniqueid(). UUID ​​, , varchar , , .

MD5 , . , hex. , , . , SHA1, MD5.

, , , .

+1

MySQL , , char/varchar, "" .

, MySQL, - , char :

mysql> select length(md5('a')), length(sha1('a'));
+------------------+-------------------+
| length(md5('a')) | length(sha1('a')) |
+------------------+-------------------+
|               32 |                40 | 
+------------------+-------------------+

.

+1

md5() .

rand() , .

:

function generateRandomKey()
{
    return base_convert(uniqid(mt_rand(), true), 16, 36);
}

: , , , . , , .

0
0
0

. , , . .

function generateSalt($length = null)
{
  if (!is_int($length) || ($length < 1)) $length = 250;
  do {
    $salt[] = chr(mt_rand(0, 255));
  } while (--$length);
  return implode('', $salt);
}

update user set salt = :salt, password = sha1(concat(:password, :salt)) where id = :id limit 1;

.

select * from user where id = :id and password = sha1(concat(:password, salt)) limit 1;
0

All Articles