开发者

Exclude certain characters generated by crypt()

I'm using cry开发者_Go百科pt() in PHP to generate a unique token string. My problem is that some tokens generated include periods (.) at the end of the token, and this is confusing for users that need to copy and paste it elsewhere... some see it as the end of a sentence rather than part of the token.

Unless I'm mistaken, I can't just replace the periods after running crypt() because it will no longer be a unique identifier.

Is there a way to restrict the characters that are output by crypt()?


If it's just a random string use a random letter generator or take a look at uniqid.


have you tought about Sha-1 instead of Crypt? would look like something like that to generate a small token.

$str = time().$token;
$result = substr(sha1($str),10)

else you may use that if you RLLY need to.

$result = preg_replace('/\./','{DOT}',crypt('mypassword'));

and to retrieve your initial

str_replace('{DOT}','.',$result)


Depending on the ultimate usage of the token, you could add delimiters to the start and end of the token so that it is more obvious to the user where the start and endpoints are.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜