Answer the question
In order to leave comments, you need to log in
How often to change hash when authenticating in php?
Good afternoon,
Please tell me I have authorization and authentication in one method
function login(string $email, string $pass, bool $isHash=false) {
#code...
}
Answer the question
In order to leave comments, you need to log in
no matter how the data is stored, they are still physically located in files, it is more logical to store the hash in the database and not more than a day (although, of course, everything here depends on its type and length).
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`login` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`last_login` int(11) UNSIGNED,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `user_tokens` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` int(11) UNSIGNED NOT NULL,
`user_agent` varchar(255) NOT NULL,
`token` varchar(255) NOT NULL,
`created` int(11) UNSIGNED NOT NULL,
`expires` int(11) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `token` (`token`),
KEY `fk_user_id` (`user_id`),
KEY `expires` (`expires`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `user_tokens`
ADD CONSTRAINT `user_tokens_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
1. Client authorization token - must be stored on the client (in cookies).
2. The lifetime of the client authorization token is 3-5 days.
3. Change/update of the client's authorization token - "transparent" for the end user.
(It was all just about a specific web browser without being tied to a user account.)
And a user authorization token (after entering a login and password) is issued only after successful client authorization.
For successful authorization, it is checked that the browser (client) is authorized, and the user login with password is correct.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question