简体   繁体   English

排除crypt()生成的某些字符

[英]Exclude certain characters generated by crypt()

I'm using crypt() in PHP to generate a unique token string. 我在PHP中使用crypt()来生成唯一的令牌字符串。 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. 除非我弄错了,否则我不能在运行crypt()之后更换句点,因为它将不再是唯一标识符。

Is there a way to restrict the characters that are output by crypt()? 有没有办法限制crypt()输出的字符?

如果它只是一个随机字符串使用随机字母生成器或看看uniqid

have you tought about Sha-1 instead of Crypt? 你有没有想过Sha-1而不是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)

根据令牌的最终用法,您可以在令牌的开头和结尾添加分隔符,以便对起点和终点所在的用户更明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM