Jump to content

[SOLVED] Insert a unique AND random 10-digit number (instead of auto-increment)


sKunKbad

Recommended Posts

I'd like a query OR the ability to set a column's properties in the database, so that as I insert a new record, the value of the field in this column would be a unique AND random 10 digit number. I'm using phpMyAdmin, as I'm not a MySQL guru. Can I set the column in the database to generate this type of number, instead of auto-increment? Currently the column is just set as INT w/ auto-increment.

 

I know I could probably do this with multiple queries to the database to confirm that a php generated random number isn't currently in use, but I'm looking for a cleaner way. Is what I want to do possible?

Well MySQL has a RAND() function, but there still can be a way to have a repeated number. I don't know of any other way but to generate a number and query the DB to see if the number exists. Too troublesome for what its worth.

 

May I ask why you wish to do that?

Well, I guess I had this idea in my head that my user id's would be more secure if they were random, and not auto-incremented. Even though the rest of the authentication system is secure, it would be much harder to guess a user's ID, in case somebody was trying to modify their cookie (or a cookie).

I am using session data and a second cookie. The data for authentication is in the session, so I guess there's no point in worrying about cookie modification. I appreciate the response. Sometimes after a long day I get foggy headed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.