A
A
Andrew2012-10-03 16:23:34
Programming
Andrew, 2012-10-03 16:23:34

Encryption problem

This question is a continuation of the question about the password recovery form on the site .

I'll take it in full.

Сделали формочку с полем для ввода почты и кнопкой «Восстановить пароль».

При нажатии на нее на почту (если такая есть в базе) отправляется ссылка вида
site.ru/fastlogin/[email protected]/823497378934270324789543

По ссылке мы определяем совпадает ли почта и хеш пароля (823497378934270324789543) с данными учетки. Если да, то человек автоматически входит на сайт. То есть перешел по ссылке и уже залогинен.

Вроде бы все очень легко и удобно. Но чувствуется что тут есть какие-то подводные камни. Может быть вы увидите их? 

The main drawback of the option I proposed earlier is that this hash is done, roughly speaking, like this

md5($pass.$salt);

and, accordingly, the hash does not change until the user changes the password.

The most important thing here, (thanks to those who responded and ++ of course :), is to give such links an expiration date of, say, one hour.

The problem is easily solved if you create a table in the database that will store such hashes with the date and time of their creation. But I would like to do without records in the database.

Actually a question.
Is it possible to provide for the possibility of introducing an expiration date in the hash?
If so, I would like to see the algorithm, or at least understand in which direction to move.

So far, only the option with Mcrypt reversible encryption comes to mind, but so far it has not been possible to get it to work correctly. The problem was described in this question habrahabr.ru/qa/25015/

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Antelle, 2012-10-03
@Antelle

You can, of course: md5($pass.$salt.$date) - and round $date to the interval you need: month, day, hour - depending on the expiration date. You can check the current and previous ones so that there is no ambush. True, it will work with an accuracy of ± the selected interval, but I think it's not scary.

U
Urvin, 2012-10-03
@Urvin

for example, the code can be formed something like this:
HEX(симметричный_шифр(array(сложный_хэш_пароля, дата_окончания_хеша, сложный_хеш_включающий_дату_и_хэш_пароля)))
Take a look at phpclasses, there are ready-made algorithms bypassing mcrypt.
Additionally, you need to take into account the get-request limit.
There is a better option: for example, you can give a period of three days, write down the code as
md5($password . $salt . date('Y-m-d', strtotime('+3 days')))
after the client clicks on the link, check the compliance of the incoming code with the code generated for the next three days.
Cons, I think, are clear.
By discarding the option of saving to the database, you lose the ability to control the number of clicks on the given link, plus you have to form a rather complex url.

W
Wott, 2012-10-04
@Wott

I prefer not to give anything at all that can be recovered to the password.
In a similar case, I made random sets like sha1 (random ()), they fell into a separate table where the key is the same random number, as well as a link to the user, date and other goodies, such as a redirect page. permalink routed incoming links, checked them, showed the password change form and redirected to the desired page, already under the given user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question