Question

I'm using crypt() 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()?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top