my bad it's all about verification result, the code works well now :
models/db.py
*pyotp verify*
auth.settings.auth_two_factor_enabled = True
def _set_two_factor(user, auth_two_factor):
return None
def verify_otp(user, otp):
import pyotp
#pyotp.random_base32() # generate random number
totp = pyotp.TOTP('4DKTQHH2V2F7T2ZO')
if totp.verify(otp):
return otp
auth.settings.two_factor_methods = [_set_two_factor]
auth.settings.two_factor_onvalidation = [verify_otp]
*google authenticator verify using pyotp*
auth.settings.auth_two_factor_enabled = True
def _set_two_factor(user, auth_two_factor):
return None
def verify_otp(user, otp):
import pyotp
#pyotp.random_base32() # generate random number
totp = pyotp.TOTP('4DKTQHH2V2F7T2ZO')
data = totp.provisioning_uri("test")
if data:
return otp
def verify_comment():
import pyotp
import qrcode
import StringIO
totp = pyotp.TOTP('4DKTQHH2V2F7T2ZO')
qr = qrcode.QRCode(
version = 1, # 1 - 40
error_correction = qrcode.constants.ERROR_CORRECT_H,
# ERROR_CORRECT_L (<= 7%), ERROR_CORRECT_M (<= 15%),
ERROR_CORRECT_Q (<= 25%), ERROR_CORRECT_H (<= 30%)
box_size = 2,
border = 1, # default 4
)
data = totp.provisioning_uri("test")
qr.add_data(data)
qr.make(fit = True)
# use an in-memory object to save
output = StringIO.StringIO()
img = qr.make_image()
img.save(output)
# and the use getvalue() method to get the string
img_qrcode = '<img src = "data:image/png;base64, %s">' %
output.getvalue().encode('base64').replace('\n', '')
return DIV(XML(img_qrcode) )
auth.messages.two_factor_comment = verify_comment()
auth.settings.two_factor_methods = [_set_two_factor]
auth.settings.two_factor_onvalidation = [verify_otp]
best regards,
stifan
--
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.