How to check if new password is different from the actual?

90 views
Skip to first unread message

Marvix

unread,
Jun 23, 2016, 11:53:47 AM6/23/16
to web2py-users
Hello,

when an user is changing his password, is it possible to check if it is equal to the current? and refuse it in that case?

Thanks!
Message has been deleted

Marlysson Silva

unread,
Jun 24, 2016, 10:23:41 AM6/24/16
to web2py-users


Yes. You can find the user logged current with : auth.user.id , and search them using the dal, i.e , db.auth_user[auth.user.id] and return the data of user, thereby verifying the field "password" ( of table )  with "form.new_password" ( name of form field that you create it.).


All this overwriting the view user/change_password ( if you don't have changed value of url retrieve password ) , and doing the operations needed.

Tip: Before submit of form user, try use .validate() at form to handled this things.

Basicaly it's this.I think :D

Limedrop

unread,
Jun 27, 2016, 5:15:45 PM6/27/16
to web2py-users
The function you are looking for is CRYPT.  You could but something like this in an on_validation function:

            if auth.user.password == CRYPT()(request.vars.new_password)[0]:
                form.errors.new_password = 'Cannot re-use password'

Marvi Benedet

unread,
Jun 28, 2016, 6:15:53 AM6/28/16
to web...@googlegroups.com
Ok, thanks to the suggestions. I'll give a try!



--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Massimo Di Pierro

unread,
Jun 28, 2016, 12:15:24 PM6/28/16
to web2py-users
Ming that the result of CRYPT()('password')[0] is not the hashed password but an object that, when converted to a string is a hashed password but when compared to a hash-ed password string, performs the comparison using the same salt and the same algorithm using the hash it is compering itself with.

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages