Create a unique random token string in Yii for the users table.
I am working on a Yii application that requires the "users" table to contain a column token, which must be a unique random row based on that user in the table (for example, will never be the same twice).
Can anyone give me some advice on this, or is there already a Yii component / extension / generator for this.
Also - what is the most optimal db column type for this?
I suggest to just use a hash that creates a long string and uses some very unique string for hashing:
sha512($userName.time().rand(1000, 9999));
Some lengths of hash hash algorithms
I like to use CSecurityManager with generateRandomString()
for this. Please be aware that it generates a string that contains the characters ~ and _
The DB column will be varchar
with the length of your row length.