OK, the problem is that you generate the password twice -- once when 
creating the form and again when processing it. Because you actually 
include the password field in the form (as readonly), the original password 
gets submitted with the form and inserted in the database. However, the 
password that gets sent in the email is the one generated the second time 
(so, not the one that gets inserted). Instead, you can do something like:

password = request.post_vars.password or generate_password(name, now)

Also, note that by including the password field in the form and simply 
making it readonly, someone can still submit a post request with their own 
custom password. If you don't want to allow that, you might instead 
consider excluding the password field altogether, and instead do something 
like:

if request.post_vars: # indicates a form submission
    db.auth_user.password.default = generate_password(name, now)
...
context = dict(..., password=db.auth_user.password.default)

Anthony

On Tuesday, August 6, 2013 5:05:31 PM UTC-4, Anthony wrote:
>
> Can you attach a minimal app that reproduces the problem (preferably in 
> the current stable version of web2py)?
>
> As an aside, instead of using your reverse() function, to reverse a 
> string, you can do mystring[::-1].
>
> Anthony
>
> On Tuesday, August 6, 2013 4:08:26 PM UTC-4, Annet wrote:
>>
>> The think the problem is caused by these functions that generate the 
>> password:
>>
>>
>> def generate_password(name,now):
>>     import random
>>     value=''
>>     chars=('ABCDEFGHJKLMNOPQRSTUVW')
>>     symbols=('~!@#$%^&*()_+-=?<>:;{}[]|')
>>     x1=random.choice(chars)
>>     y=len(name)
>>     if y<3:
>>         x2=reverse(name)
>>     else:
>>         z=y-3
>>         x2=reverse(name[z:y])
>>     x3=random.choice(chars)
>>     x4=random.choice(symbols)
>>     x5=reverse(now)
>>     value=value+x1+x2+x3+x4+x5
>>     return value
>>
>>
>> def reverse(x):
>>     i=len(x)
>>     value=''
>>     while i > 0:
>>         value=value+x[i-1]
>>         i=i-1
>>     return value
>>
>>
>> When I replace return value with return '6#TestValue'
>> The functions works i.e. it inserts '6#TestValue' into the auth_user table
>> and sends the value to the user.
>>
>> I hope you know what's wrong with this value this function returns?
>>
>>
>> Kind regards,
>>
>> Annet
>>
>>
>>

-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to