Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a Unique Key

Tags:

What’s the best way of generating a unique key, that can’t be guessed easily?

I would like to create a unique key for both account activation and referral purposes, that includes a checksum to help prevent users from easily guessing other users activation or referral keys.

Also, in PHP is it possible to create you own session key? If so, how would you make this unique?

Any help is greatly appreciated.

like image 527
user826855 Avatar asked Jul 03 '11 17:07

user826855


People also ask

How are unique keys generated?

All the candidate keys of a relation can uniquely identify the records of the relation, but only one of them is used as the primary key of the relation. The remaining candidate keys are called unique keys because they can uniquely identify a record in a relation. Unique keys can consist of multiple columns.

How do I create a unique key in Excel?

You can generate a unique value using a formula in the spreadsheet. An ID must be a value, not a formula, though, so copy (Ctrl+C) and paste as plain text (Shift+Ctrl+V) the result of the formula calculation into the cell meant to contain the new ID. That's all there is to it!

How do I add a unique key in React?

Firstly let's run npm i uuidv4 to download and install the uuidv4 Node package. We can now import it with import { uuid } from uuid4 . Finally we can add a Key prop to the <li> elements and simply call the function uuid() . This function returns a string which is a UUID.


1 Answers

Don't over-complicate it:

$key = md5(microtime().rand()); 
like image 89
AlienWebguy Avatar answered Sep 24 '22 19:09

AlienWebguy