You might not need to do this in the way you are suggesting (depending on
your application).  I'm not sure why you feel you need to combine the
autoincrement with the hash into the same field.  Does it really do harm if
two records have the same hash?

It might work as well to have two separate fields, one that contains the
AUTOINCREMENT value, and a second field containing the SHA1.

The most traditional approach to using cryptographic hashes is to have a bit
of randomness (a string with at least 160 bits of information for SHA1), and
to form the hash as a function of some known quantity plus the randomness.
If + is the concatenation operator, you might use:

hashfield = SHA1(randomness + id + randomness);

As long as the "randomness" is known only to you, there is no way for an
attacker to make the mapping from id to the hashfield.

What do you mean by security?  What are you trying to protect against?

On 8/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Isn't there a chance that you could get a ID that is the same as one
> already in use? and if this happens what happens on the insert?
>
>
> Wishing you the best you know you deserve,
>
> ______________________
> Lucas Heuman
> Web Developer
> Ricomm Systems Inc.
> FAA, WJHTC/Bldg 300, 3nd Fl., L33
> Atlantic City Int'l Airport, NJ  08405
> Phone 609.485.5401
>
>
>
> "Olexandr Melnyk" <[EMAIL PROTECTED]>
> 08/07/2007 08:19 AM
>
> To
> mysql@lists.mysql.com
> cc
>
> Subject
> Fwd: auto increment format
>
>
>
>
>
>
> You can do that using a "before insert" trigger, something like (untested)
> :
>
> CREATE TRIGGER test1bi
> BEFORE INSERT ON test1
> FOR EACH ROW BEGIN
>    NEW.ID = COALESCE( NEW.ID, SHA1(CAST(RAND() AS CHAR)))
> END;
>
>
> 2007/8/7, shivendra <[EMAIL PROTECTED]>:
> >
> >
> > Hi, I'm looking for some basic help. I am developing a MySQL database
> and
> > want to auto increment a field, but I don't want it to just count 1,2,3,
> > etc. I want the field to be a combination of letters and numbers, at
> least
> > 8
> > digits long, completely random for security porposes, but do this
> > automatically, everytime a record is added. For example, ord5001,
> ord5002,
> > ord5003, etc. Does anyone know how to do this in MySQL?
> > --
> > View this message in context:
> > http://www.nabble.com/auto-increment-format-tf4229677.html#a12032917
> > Sent from the MySQL - General mailing list archive at Nabble.com.
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:     http://lists.mysql.com/[EMAIL PROTECTED]
> >
> >
>
>
> --
> Sincerely yours,
> Olexandr Melnyk
> http://omelnyk.net/
>
>

Reply via email to