PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

[FIXED] Create a unique random token string in Yii for users table

 March 03, 2022     database, php, token, uniqueidentifier, yii     No comments   

Issue

I am working on a Yii app that requires the 'users' table to have a column 'token' that will need to be a unique random string that is based upon that user in the table (eg there will never be the same token twice).

Can anyone give me some tips on doing this, or are there a Yii component/extension/generator already setup to do this.

Also - what is the most optimised db column type for this?


Solution

I suggest just to use hash, that produces long string and use some very unique string to be hashed:

sha512($userName.time().rand(1000, 9999));

Some PHP hash algorithms lengths



Answered By - Justinas
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing