Answer the question
In order to leave comments, you need to log in
How to automatically generate a universal identification key in the database by the type of automatic ID when registering a user on the site?
Hello colleagues!
The essence of the question is this: I am creating a registration / authorization system on the site, how to properly configure the database field, so that when a user enters the database in a certain field, his personal identification key is generated, which in the future he can use to authorize on the site? You need something like the ID field, but using not only numbers, but also capital letters of the English alphabet, this key must also be unique and generated completely randomly.
For example, in the "key" field during registration, the user should generate a similar key:
DF09DK817F61HYDR
Thank you for your help!
Answer the question
In order to leave comments, you need to log in
Can you use something like this in PHP?
<?php
$random_string = strtoupper(bin2hex(random_bytes(12)));
echo $random_string;
according to your conditions, this function:
function token($data) {
return mb_substr(strtoupper(preg_replace('~[^-a-z0-9_]+~','', password_hash(strtolower(iconv("utf-8", "us-ascii//TRANSLIT", trim(preg_replace('~[^\\pL0-9_]+~u', '-', $data), "-"))),PASSWORD_BCRYPT, ['cost' => 12,]))),4,16);
}
$first_name = 'Василий';
$last_name = 'Petrov';
$date = date('h:i:s A');
$token = token($first_name . $last_name . $_SERVER['HTTP_USER_AGENT'].$date);
echo 'токен: ' .$token . ' длина: '. strlen($token). "\n";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question