You have various problems:
1) form=SQLFORM(....) is a create form. when you form.accept it
creates a new record. I do not think that is what you want.
2) your cannot for form.accepts(form,...) it is form.accepts
(request.vars,...) or FORM.accepts(form,request.vars,...)
3) You have this:
rows=userdb(userdb.user.username==form.vars.username)\
(userdb.user.password==form.vars.password)\
(userdb.user.password=='').select()
which is equivalent to
rows=userdb((userdb.user.username==form.vars.username)& \
(userdb.user.password==form.vars.password)& \
(userdb.user.password=='')).select()
but this query can never be true. the password cannot be both the
form.vars.password and ''.
I think you want
def log_in():
form=SQLFORM(userdb.user,fields=['username','password'])
if FORM.accepts(form,request.vars,session):
if userdb(userdb.user.username==form.vars.username)\
(userdb.user.password==form.vars.password).count():
response.flash = "logged in"
else:
response.flash = "invalid username/password"
return dict(form=form)
This assumes the username and password are in the database and the
userdb.user.password.requires is NOT set to CRYPT(). I.e. you keep the
password in the clear.
You should look into
http://mdp.cti.depaul.edu/examples/static/t2.pdf
Massimo
On Jan 28, 9:37 pm, MadWalker <[email protected]> wrote:
> i got some problem and i still not able to do the username and
> password check
>
> i was told to do this way
>
> def log_in():
> form=SQLFORM(userdb.user,fields=['username','password'])
>
> if form.accepts(form,request.vars,session):
> rows=userdb(userdb.user.username==form.vars.username)\
> (userdb.user.password==form.vars.password)\
> (userdb.user.password=='').select()
> if rows:
> response.flash = "logged in"
> else:
> response.flash = "invalid username/password"
> return dict(form=form)
>
> but it did not work at all,
> can anyone please help?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---