Hello, Massimo gave me some clues and I think I've found the solution: I was debugging my code and saw that this line: db.auth_user.password.validate(password) returns a 2-tupla: (crypter password, error)
In my code (and in all examples I've seen through Internet), this 2-tuple is stored in the database. So what you see in the database is: |pbkdf2(1000,20,sha512)$90718911d716ab40$9ab041ebf5432bb9432cef16165865d320123e0a|None| The password and the error are stored in the same field. Everything is ok, but I am storing the wrong thing. So when I try to log in, the password field is not a password but a 2-tuple, it's strange to web2py and it crashes. What I've done is: passwordAux = db.auth_user.password.validate(password) if passwordAux[1] != None ...insert(..., password=password[0]) And now, this is working. Now, what is stored in the databse is the password only: pbkdf2(1000,20,sha512)$90718911d716ab40$9ab041ebf5432bb9432cef16165865d320123e0a and the log in works perfectly. Kind regards! El jueves, 20 de diciembre de 2012 20:10:41 UTC+1, Wonton escribió: > > If you don't mind I could send you my project to your email directly. > > El jueves, 20 de diciembre de 2012 16:14:12 UTC+1, Massimo Di Pierro > escribió: >> >> If your data is not confidential, any chance you send me your application? >> >> To me this looks like corrupted data in database as if the password field >> was at some pointed treated as type='list:string' and than changed back to >> type='password'. Is it possible? >> >> Massimo >> >> On Wednesday, 19 December 2012 11:28:15 UTC-6, Wonton wrote: >>> >>> Yes, of course. This is my ticket: >>> >>> Error ticket for "dianaappv1" Ticket ID >>> >>> 127.0.0.1.2012-12-19.18-24-12.5d2b292c-7e9a-4281-a9f7-bb9aa17bbd0c >>> <type 'exceptions.ValueError'> unsupported hash type >>> |pbkdf2(1000,20,sha512) Versión web2py™ (2, 2, 1, >>> datetime.datetime(2012, 10, 21, 16, 57, 4), 'stable') Python Python >>> 2.7.1: /usr/bin/python Traceback >>> >>> 1. >>> 2. >>> 3. >>> 4. >>> 5. >>> 6. >>> 7. >>> 8. >>> 9. >>> 10. >>> 11. >>> 12. >>> 13. >>> 14. >>> 15. >>> 16. >>> 17. >>> 18. >>> 19. >>> 20. >>> 21. >>> 22. >>> 23. >>> 24. >>> 25. >>> 26. >>> 27. >>> 28. >>> >>> Traceback (most recent call last): >>> File "/Applications/web2py/gluon/restricted.py", line 212, in restricted >>> exec ccode in environment >>> File >>> "/Applications/web2py/applications/dianaappv1/controllers/default.py" >>> <https://127.0.0.1:8000/admin/default/edit/dianaappv1/controllers/default.py>, >>> line 101, in <module> >>> File "/Applications/web2py/gluon/globals.py", line 188, in <lambda> >>> self._caller = lambda f: f() >>> File >>> "/Applications/web2py/applications/dianaappv1/controllers/default.py" >>> <https://127.0.0.1:8000/admin/default/edit/dianaappv1/controllers/default.py>, >>> line 27, in public_call >>> return servicios_publicos() >>> File "/Applications/web2py/gluon/tools.py", line 4387, in __call__ >>> return self.serve_json(request.args[1:]) >>> File "/Applications/web2py/gluon/tools.py", line 4197, in serve_json >>> s = universal_caller(self.json_procedures[args[0]], *args[1:], **d) >>> File "/Applications/web2py/gluon/tools.py", line 3889, in universal_caller >>> return f(**arg_dict) >>> File >>> "/Applications/web2py/applications/dianaappv1/controllers/default.py" >>> <https://127.0.0.1:8000/admin/default/edit/dianaappv1/controllers/default.py>, >>> line 65, in login >>> user = auth.login_bare(usuario, password) >>> File "/Applications/web2py/gluon/tools.py", line 1789, in login_bare >>> if not user.registration_key and password == user[passfield]: >>> File "/Applications/web2py/gluon/validators.py", line 2636, in __eq__ >>> h = simple_hash(self.password, key, salt, digest_alg) >>> File "/Applications/web2py/gluon/utils.py", line 74, in simple_hash >>> h = hashlib.new(digest_alg) >>> File >>> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", >>> line 121, in __hash_new >>> return __get_builtin_constructor(name)(string) >>> File >>> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", >>> line 88, in __get_builtin_constructor >>> raise ValueError('unsupported hash type %s' % name) >>> ValueError: unsupported hash type |pbkdf2(1000,20,sha512) >>> >>> Error snapshot [image: help] >>> >>> <type 'exceptions.ValueError'>(unsupported hash type >>> |pbkdf2(1000,20,sha512)) >>> >>> inspect attributes >>> Frames >>> >>> - >>> >>> *File /Applications/web2py/gluon/restricted.py in restricted at line >>> 212* código argumentos variables >>> - >>> >>> *File >>> /Applications/web2py/applications/dianaappv1/controllers/default.py in >>> <module> at line 101* código argumentos variables >>> - >>> >>> *File /Applications/web2py/gluon/globals.py in <lambda> at line 188* >>> código argumentos variables >>> - >>> >>> *File >>> /Applications/web2py/applications/dianaappv1/controllers/default.py in >>> public_call at line 27* código argumentos variables >>> - >>> >>> *File /Applications/web2py/gluon/tools.py in __call__ at line 4387* >>> código argumentos variables >>> - >>> >>> *File /Applications/web2py/gluon/tools.py in serve_json at line 4197* >>> código argumentos variables >>> - >>> >>> *File /Applications/web2py/gluon/tools.py in universal_caller at >>> line 3889* código argumentos variables >>> - >>> >>> *File >>> /Applications/web2py/applications/dianaappv1/controllers/default.py in >>> login at line 65* código argumentos variables >>> - >>> >>> *File /Applications/web2py/gluon/tools.py in login_bare at line 1789* >>> código argumentos variables >>> - >>> >>> *File /Applications/web2py/gluon/validators.py in __eq__ at line 2636 >>> * código argumentos variables >>> - >>> >>> *File /Applications/web2py/gluon/utils.py in simple_hash at line 74* >>> código argumentos variables >>> - >>> >>> *File >>> >>> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py >>> >>> in __hash_new at line 121* código argumentos variables >>> - >>> >>> *File >>> >>> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py >>> >>> in __get_builtin_constructor at line 88* código argumentos variables >>> Function argument list >>> >>> (name='|pbkdf2(1000,20,sha512)') >>> Code listing >>> >>> 83. >>> 84. >>> 85. >>> 86. >>> 87. >>> 88. >>> >>> 89. >>> 90. >>> 91. >>> 92. >>> >>> if bs == '512': >>> return _sha512.sha512 >>> elif bs == '384': >>> return _sha512.sha384 >>> >>> raise ValueError('unsupported hash type %s' % name) >>> >>> >>> >>> def __get_openssl_constructor(name): >>> try: >>> >>> Variables name '|pbkdf2(1000,20,sha512)' builtinValueError <type >>> 'exceptions.ValueError'> >>> >>> Context >>> >>> locals request session response >>> In file: >>> /Applications/web2py/applications/dianaappv1/controllers/default.py >>> >>> 1. >>> 2. >>> 3. >>> 4. >>> 5. >>> 6. >>> 7. >>> 8. >>> 9. >>> 10. >>> 11. >>> 12. >>> 13. >>> 14. >>> 15. >>> 16. >>> 17. >>> 18. >>> 19. >>> 20. >>> 21. >>> 22. >>> 23. >>> 24. >>> 25. >>> 26. >>> 27. >>> 28. >>> 29. >>> 30. >>> 31. >>> 32. >>> 33. >>> 34. >>> 35. >>> 36. >>> 37. >>> 38. >>> 39. >>> 40. >>> 41. >>> 42. >>> 43. >>> 44. >>> 45. >>> 46. >>> 47. >>> 48. >>> 49. >>> 50. >>> 51. >>> 52. >>> 53. >>> 54. >>> 55. >>> 56. >>> 57. >>> 58. >>> 59. >>> 60. >>> 61. >>> 62. >>> 63. >>> 64. >>> 65. >>> 66. >>> 67. >>> 68. >>> 69. >>> 70. >>> 71. >>> 72. >>> 73. >>> 74. >>> 75. >>> 76. >>> 77. >>> 78. >>> 79. >>> 80. >>> 81. >>> 82. >>> 83. >>> 84. >>> 85. >>> 86. >>> 87. >>> 88. >>> 89. >>> 90. >>> 91. >>> 92. >>> 93. >>> 94. >>> 95. >>> 96. >>> 97. >>> 98. >>> 99. >>> 100. >>> 101. >>> 102. >>> >>> # -*- coding: utf-8 -*- >>> # this file is released under public domain and you can use without >>> limitations >>> >>> ######################################################################### >>> ## This is a samples controller >>> ## - index is the default action of any application >>> ## - user is required for authentication and authorization >>> ## - download is for downloading files uploaded in the db (does streaming) >>> ## - call exposes all registered services (none by default) >>> ######################################################################### >>> servicios_publicos=Service() >>> servicios_privados=Service() >>> >>> def random_password(): >>> import string >>> import random >>> password = '' >>> specials=r'!...@#$*?' >>> for i in range(0,2): >>> password += random.choice(string.lowercase) >>> password += random.choice(string.uppercase) >>> password += random.choice(string.digits) >>> # password += random.choice(specials) >>> return ''.join(random.sample(password,len(password))) >>> >>> def public_call(): >>> return servicios_publicos() >>> >>> @auth.requires_login() >>> def private_call(): >>> return servicios_privados() >>> >>> @servicios_publicos.json >>> def registra(usuario, email, password): >>> respuesta = {} >>> estado = 'OK' >>> mensaje = '' >>> tipoError = 0 >>> #Comprueba si hay otro usuario con el mismo nombre >>> if db(db.auth_user.username == usuario).count() != 0: >>> estado = 'Error' >>> tipoError = 1 >>> #Comprueba si hay otro usuario con el mismo email >>> if db(db.auth_user.email == email).count() != 0: >>> estado = 'Error' >>> tipoError = tipoError + 2 >>> #Registrar >>> if estado == 'OK': >>> db.auth_user.insert(username=usuario, email=email, >>> password=db.auth_user.password.validate(password)) >>> mensaje = 'El registro se ha realizado correctamente.' >>> else: >>> if tipoError == 1: >>> mensaje = 'El usuario ya existe.' >>> elif tipoError == 2: >>> mensaje = 'El email ya existe.' >>> else: >>> mensaje = 'El usuario y el email ya existen.' >>> respuesta['estado'] = estado >>> respuesta['mensaje'] = mensaje >>> return respuesta >>> >>> @servicios_publicos.json >>> def login(usuario, password): >>> respuesta = {} >>> user = auth.login_bare(usuario, password) >>> if not user: >>> respuesta['estado'] = 'Error' >>> respuesta['mensaje'] = 'Nombre de usuario o contraseña incorrecta' >>> else: >>> respuesta['estado'] = 'OK' >>> respuesta['mensaje'] = 'Login correcto' >>> return respuesta >>> >>> @servicios_publicos.json >>> def recupera_contrasenya(usuario): >>> nueva_contrasenya = random_password() >>> respuesta = {} >>> fila = db(db.auth_user.username == usuario) >>> if fila.count() == 0: >>> respuesta['estado'] = 'Error' >>> respuesta['mensaje'] = 'No existe el usuario' >>> else: >>> >>> fila.update(password=db.auth_user.password.validate(nueva_contrasenya)) >>> datosFila = fila.select() >>> destino = datosFila[0].email >>> enviado = mail.send(to=[destino], >>> subject='Recuperación de contraseña', >>> message='Se te ha creado una nueva contraseña. Es esta ' + >>> nueva_contrasenya) >>> if enviado: >>> respuesta['estado'] = 'OK' >>> respuesta['mensaje'] = 'Se ha enviado la contraseña a su correo >>> electrónico.' >>> else: >>> respuesta['estado'] = 'Error' >>> respuesta['mensaje'] = 'La contraseña no se ha podido enviar, >>> reinténtelo más tarde' >>> return respuesta >>> >>> #@servicios_privados.json >>> #def metodo_privado(): >>> # return 'private' >>> >>> response >>> <https://127.0.0.1:8000/examples/global/vars/response>._vars=response >>> <https://127.0.0.1:8000/examples/global/vars/response>._caller(public_call) >>> >>> >>> >>> El miércoles, 19 de diciembre de 2012 18:09:25 UTC+1, Massimo Di Pierro >>> escribió: >>>> >>>> Can you please show me the complete traceback? >>>> I cannot reproduce this and I this error is not generated from a web2py >>>> function. >>>> >>>> On Tuesday, 18 December 2012 11:11:51 UTC-6, Massimo Di Pierro wrote: >>>>> >>>>> Can I see you models? Are you changing the validator for >>>>> db.auth_user.password? >>>>> Your error says: >>>>> >>>>> <type 'exceptions.ValueError'> unsupported hash type >>>>> |pbkdf2(1000,20,sha512) >>>>> >>>>> I do not understand where | in |pbkdf2 would come from. >>>>> >>>>> >>>>> On Tuesday, 18 December 2012 09:33:12 UTC-6, Wonton wrote: >>>>>> >>>>>> Hi Massimo!! >>>>>> >>>>>> I'm using version 2.2.1 (2012-10-21 16:57:04) stable. I dowloaded it >>>>>> last week. >>>>>> >>>>>> El martes, 18 de diciembre de 2012 16:26:29 UTC+1, Massimo Di Pierro >>>>>> escribió: >>>>>>> >>>>>>> Which web2py version? The error suggests you are using an older >>>>>>> web2py version with newly created database of records. >>>>>>> >>>>>>> Massimo >>>>>>> >>>>>>> On Monday, 17 December 2012 14:59:02 UTC-6, Wonton wrote: >>>>>>>> >>>>>>>> Hello everyone, >>>>>>>> >>>>>>>> I'm developing a backend site with web2py. I have 2 web services, >>>>>>>> one to register a user and a second one to login the user. >>>>>>>> This is the first one: >>>>>>>> >>>>>>>> def register(user, email, password): >>>>>>>> db.auth_user.insert(username=user, email=email, >>>>>>>> password=db.auth_user.password.validate(password)) >>>>>>>> ... >>>>>>>> return 'OK' >>>>>>>> >>>>>>>> It's working ok and the users are created without problem. >>>>>>>> >>>>>>>> This is the second one: >>>>>>>> >>>>>>>> def login(user, password): >>>>>>>> response = auth.login_bare(user, password) >>>>>>>> if not response: >>>>>>>> message = 'Error' >>>>>>>> else: >>>>>>>> message = 'OK' >>>>>>>> return message >>>>>>>> >>>>>>>> With this service I have the following error: >>>>>>>> <type 'exceptions.ValueError'> unsupported hash type >>>>>>>> |pbkdf2(1000,20,sha512) >>>>>>>> >>>>>>>> I've tried to find any solution to this problem without success. >>>>>>>> >>>>>>>> Any of you has any idea of what is happening? >>>>>>>> >>>>>>>> Thank you very much and kind regards! >>>>>>>> >>>>>>>> Wonton >>>>>>>> >>>>>>> --