I'm trying to design a simple user table with a primary key userid
, and then another table that uses userid
as a foreign key to the users
table. Do I have the right idea here?
CREATE TABLE `users` (
`userid` INT(6) NOT NULL,
`username` VARCHAR(50) NOT NULL,
`password` VARCHAR(50) NOT NULL,
`date_join` DATE NOT NULL, <- should I just make this CURDATE instead?
`user_handle` VARCHAR(50) NOT NULL,
`date_modified` DATE NOT NULL,
PRIMARY KEY (`userid`)
)
1) How can I make userid auto increment?
2) How do you store passwords as an MD5 hash? Also, I've read various coders strongly recommending brcrypt, thoughts?
3) How can I set the default user_handle
to be the first part of an email before the @
symbol? Such that john@smith.com
would yield a user handle of john
.
4) Any extra security measures I should take when designing a user database?
5) The foreign key in other tables assocated with users would need a foreign key that points to userid
in users?
Thanks a lot guys, I hope that's not too many questions!