[英]create unique string from two other strings (one is unique and other is not)
我想從兩個字符串( string a
和string b
生成一個唯一鍵。 string a
已經是8至20長度的唯一密鑰chars
,而串b不具有8至20相同的長度獨特chars
。 目標密鑰必須很難猜測,唯一且具有10個字符的固定長度。 我嘗試了mad5()
, uniqueid()
和rand()
函數的一些組合,但是每次目標字符串超過10個chars
的限制。 如何獲得10個chars
密鑰?
您可以將a和b中的所有字符放入一個數組中,對數組進行隨機組合,然后將它們隨機從0循環到9
假設您的目標密鑰存儲在數據庫中。
$string1 = 'some_unique_string';
$string2 = 'any_other_string';
do{
$target_string = sub_str(str_shuffle($string1.$string2),0,10);
$sql='select * from table_name where targetKeyColoumn = "'.$$target_string.'"'; //add sql injection prevention
$result = mysqli_query($dbConectionResource, $sql);
$row_cnt = mysqli_num_rows($result);
}while($row_cnt); //if its 0, come out from loop
echo $target_string;
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.