This is correct?
from gluon.validators import CRYPT
password = CRYPT()(str(self.db.auth_user.password.validate(password)[0]))[0]
Em terça-feira, 7 de maio de 2013 17h31min58s UTC-3, Dirk escreveu:
>
> json.loads() returns a unicode string which
>
> *db.auth_user.password.validate() doesn't like -- try converting your
> password variable to a string first as follows:*
>
>
>
>
> *password = str(db.auth_user.password.validate(str(password))[0])Don't
> forget to str() the result of the db.auth_user.password.validate()[0] too
> since it returns an instance of gluon.validators.LazyCrypt and keep the
> passwords 4+ in length.HTH, D*
> On Tuesday, May 7, 2013 12:42:58 PM UTC-4, Stan Lexow wrote:
>>
>>
>>
>>
>>
>>
>>
>> *Inserting a new user programmatically with web2py, v2.4.6I apologize for
>> the re post. I have read many threads on this subject, including several
>> from Massimo, but I am still having trouble inserting a new user record.I
>> just upgraded web2py to 2.4.6 from version 2012/3/4 1.99.7. The insert was
>> working before the upgrade.When I execute the following code I receive the
>> traceback belowcode fragment:...password =
>> json.loads(request.vars.password).decode('unicode-escape')password =
>> str(db.auth_user.password.validate(password)[0])...db.auth_user.insert(first_name=first_name,
>>
>> last_name=last_name, email=email, password=password)...The above code was
>> tried with and without " *
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *.decode('unicode-escape') " Error: Traceback (most recent call
>> last):File
>> "/Users/foo/Desktop/dev/web2py/applications/init/controllers/default.py",
>> line 599, in manageUsers
>> password=str(db.auth_user.password.validate(password)[0]).decode('unicode-escape'))File
>>
>> "/Users/foo/Desktop/dev/web2py/gluon/validators.py", line 2760, in str
>> hashed = simple_hash(self.password, key, salt, digest_alg)File
>> "/Users/foo/Desktop/dev/web2py/gluon/utils.py", line 87, in simple_hash
>> int(keylen), get_digest(alg))File
>> "/Users/foo/Desktop/dev/web2py/gluon/contrib/pbkdf2.py", line 55, in
>> pbkdf2_hex return pbkdf2_bin(data, salt, iterations, keylen,
>> hashfunc).encode('hex')File
>> "/Users/foo/Desktop/dev/web2py/gluon/contrib/pbkdf2.py", line 65, in
>> pbkdf2_bin mac = hmac.new(data, None, hashfunc)File
>> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py",
>> line 133, in new return HMAC(key, msg, digestmod)File
>> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py",
>> line 72, in init self.outer.update(key.translate(trans_5C))TypeError:
>> character mapping must return integer, None or unicodeImportant: When I
>> execute the following code from the web2py shell using “ python web2py.py
>> -S init -M “, I do not get an error and the insert works as expected.email
>> = '[email protected]'first_name='first'last_name=’last'password='flast123'
>> # web2py database
>> portion...db.auth_user.insert(first_name=first_name, last_name=last_name,
>> email=email,
>>
>> password=str(db.auth_user.password.validate(‘mySecretPassword')[0]))Any
>> insight is greatly appreciated!!Thanks in advance,Stan*
>>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.