0

Suppose I have following table -

id   name  
--   ----
1    kshitiz

Is it possible to define another column that is the md5 sum (or some other hash) of values in the previous two columns?

id   name    hash
--   ----    ----
1    kshitiz 392b6be97993de246fe188ac5d0052a7

1 Answer 1

1

if you are talking of column definition as in create table, there isn't a data type for hash.

However, it's best to use binary(20) and unhex function to convert your sha-1 into a binary data type because it saves a lot of space.

create table user(
id int primary key auto_increment not null,
username varchar(50),
password binary(20)
);

insert into user(username) values('ndefontenay');

update user set
password = unhex(sha1(concat(last_insert_id(),username)))
where id = last_insert_id();

select upper(sha1(concat(1,'ndefontenay'))) as "on insert",hex(password) as "on retrieve"
from user
where id = 1;
1
  • Not quite sure why I can't format my answer. The menu is gone. Aug 21, 2013 at 6:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.