簡體   English   中英

從另外兩個字符串創建唯一的字符串(一個是唯一的,另一個不是)

[英]create unique string from two other strings (one is unique and other is not)

我想從兩個字符串( string astring 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM