Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5932461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:50:14+00:00 2026-05-22T14:50:14+00:00

All, This is a fairly specific question and I suspect there’s no perfect answer.

  • 0

All,

This is a fairly specific question and I suspect there’s no perfect answer.

Goal: For a website, I want to generate during user registration a unique string that is incremental (so no GUID). This string is going to be primary key in the user table in the database, and is also going to be used to salt a password before hashing. The userID is not visible by the user – it’s used only for internal purposes.

Question: Where and how should I generate the string? Options I’m considering are:

1 – Generate in the PHP code using uniqid(“”).
I can set up a loop that re-attempts to insert the new record as long as the insert fails (i.e., when the userID already exists, if two users attempt to register exactly at the same microsecond…).
Pros:

  • I can use the userID to salt the pw without having to hit the db. Ideal case for user registration is a single db transaction.
  • The string has a known format (length).
  • The string is not random but is complex enough to be a good salt.

Con:

  • The string doesn’t contain any easily available information that I could otherwise find useful. That fact alone might negate any benefit from it being sequential, since I’m less likely to query for ranges of unique IDs if they are otherwise meaningless.
  • I risk collisions if code is distributed. (SQL will prevent actual collisions from being registered, but it might slow down things.)

2 – Generate in MySQL using an auto-increment identity or similar field.
Pros:

  • No risk of collision slowing down the registration.
  • The number generated contains useful info, i.e., the rank of the user.

Cons:

  • The field doesn’t add much complexity at first as a salt for the pw hashing process.
  • String length varies overtime.
  • I need to query the db for the string in order to do the salting and hashing – so each registration hits the table twice at least. (I could come up with a different string generation in php to create a salt, but then I would have one more column).

I don’t have enough knowledge or experience to weigh those pros and cons, and I’m sure I’m missing some. I would appreciate any help you may bring…

Cheers,

JDelage

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:50:15+00:00Added an answer on May 22, 2026 at 2:50 pm

    Please see Ahmet alp Balkan’s response to my other question here: PHP – Is uniqid("") a good practical solution to generate a unique and sequential key server side? . The answer suggest that uniqid(“”) is the right approach as the risk of collision during a given microsecond is minimal to nonexistent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While I understand this question is fairly vague since I'm not giving you all
First of all, I'm fairly new to Java, so sorry if this question is
this question is fairly DevExpress-specific. I use a NavBar control with the standard SkinExplorerBarView
So this is probably a fairly easy question to answer but here goes anyway.
first of all this is my third question about web services here and i
I am new to all this, but here goes: There is an apple file
This is a fairly simple question. Basically, I'm having a program send HardWare ID's
This is a more specific question to follow up on [another question that I
I think this question is probably fairly simple, but I've been searching around and
Sorry if this is too easy of a question, but I'm fairly new to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.