Google Authentication的实现 - Odoo 安全登录
在前边的一篇文章中,我们提到了利用二次验证增强Odoo登录的可靠性:http://www.cnblogs.com/kfx2007/p/6023991.html
今天我们来具体实现这一步:
后端的实现
我们需要一个地方来存储二次验证的安全码,拓展用户字段:
class res_users(models.Model):
_inherit='res.users' enable_google_auth = fields.Boolean(u'启用Google两步验证') otp_str = fields.Char('QR Codes')
google_auth_img = fields.Binary('Google Authontication QR',compute="_get_qr_img")
安全码采用随机字符,并用二维码的方式呈现出来:
@api.one
def btn_gen(self):
base32 = pyotp.random_base32()
self.otp_str = base32 @api.one
def _get_qr_img(self):
#check login
if '@' not in self.login:
raise except_orm(_('Error!'),_('Invlid Login!'))
totp = pyotp.TOTP(self.otp_str)
qrcodes = totp.provisioning_uri(self.login)
img = qrcode.make(qrcodes)
buf = StringIO.StringIO()
img.save(buf,'PNG')
self.google_auth_img = buf.getvalue().encode('base64')
这里需要注意的是,web页面并不能直接将python的image展示出来,需要将其用base64 encode之后展示出来。
前端的实现
根据个人需求,前端的验证方式可以有多种,这里以密码+6位随机数字的方式为例:
class google(openerp.addons.web.controllers.main.Home):
@http.route('/web/login',type='http',auth='public',website=True)
def web_login(self,*args,**kargs):
if request.httprequest.method=='POST' and not request.params.get('qsso'):
#Check Google Authentication
uids = request.registry.get('res.users').search(request.cr,openerp.SUPERUSER_ID,[('login','=',request.params['login'])])
qcontext={}
if not len(uids):
qcontext['error'] = _("User doesn't exist! Please contact system administrator!")
user = request.registry.get('res.users').browse(request.cr,openerp.SUPERUSER_ID,uids)
if user.enable_google_auth and user.otp_str:
totp = pyotp.TOTP(user.otp_str)
otpcode = totp.now()
check_code = request.params['password'][-6:]
check_passwd = request.params['password'][:-6]
if request.params['password'][-6:] == otpcode:
request.params['password']=check_passwd
return super(google,self).web_login(*args,**kargs)
else:
qcontext['error'] = 'Your Google Authentication Failed!'
return request.render('web.login', qcontext)
return super(google,self).web_login(*args,**kargs)
主要的思路是当用户传过来的密码 截取后6位与生成的6位验证码进行验证,如果验证通过再去验证前几位的密码字符,否则直接不允许登录。
效果图如下:

登录界面失败以后的界面:

Google Authentication的实现 - Odoo 安全登录的更多相关文章
- ldap + kerberos + google authentication 实现两步验证
第一步:ldap + kerberos 整合 ,参考之前的文章 第二步:google authentication 安装配置,参考之前的文章 第三步:整合 ldap + kerberos + goo ...
- centos 6 SSH配置Google Authentication 验证
创建工作目录: mkdir google-authentication 1. 安装二维码生成依赖 #wget http://fukuchi.org/works/qrencode/qrencode-3. ...
- Google Authentication 机制原理
Google Authenticator,谷歌身份认证器,Google公司推出的一款动态口令工具,旨在解决大家Google账户遭到恶意攻击的问题.该工具主要基于TOTP(Time-Based One- ...
- 利用OTP为odoo增强安全访问
两次验证是广泛应用于各大站点的验证机制,我们今天利用Google Authentication来实现Odoo的两次验证,防止撞库或密码泄露等引起的安全问题. 1. 二次验证的原理 参见 http:// ...
- 【Linux】使用Google Authenticator 实现ssh登录双因素认证
一般来说,使用ssh远程登录服务器,只需要输入账号和密码,显然这种方式不是很安全.为了安全着想,可以使用GoogleAuthenticator(谷歌身份验证器),以便在账号和密码之间再增加一个验证码, ...
- Linux下部署SSH登录时的二次身份验证环境记录(利用Google Authenticator)
一般来说,使用ssh远程登录服务器,只需要输入账号和密码,显然这种方式不是很安全.为了安全着想,可以使用GoogleAuthenticator(谷歌身份验证器),以便在账号和密码之间再增加一个验证码, ...
- Centos6.5SSH登录使用google二次验证
一般ssh登录服务器,只需要输入账号和密码,但为了更安全,在账号和密码之间再增加一个google的动态验证码.谷歌身份验证器生成的是动态验证码,默认30秒更新 工具/原料 CentOS 6.5 X ...
- ssh密码登录+ Google Authenticator 实现双向认证
通常我们直接通过ssh输入密码连接服务器,但这样很容易出现暴力破解情况,所以我们可以结合google的动态认证+ssh密码,这样能够大大的提升登陆的安全. 简单来说,就是当用户通过ssh登陆系统时,先 ...
- Linux下使用Google Authenticator配置SSH登录动态验证码
1.一般ssh登录服务器,只需要输入账号和密码.2.本教程的目的:在账号和密码之间再增加一个验证码,只有输入正确的验证码之后,再输入密码才能登录.这样就增强了ssh登录的安全性.3.账号.验证码.密码 ...
随机推荐
- 正则表达式 判断 ip:端口 形式
<html> <head> </head> <body> ip:port<input type="" name="z ...
- nginx优化
此文章非原创,出自鸟哥之手~ http://blog.chinaunix.net/uid-25266990-id-2985541.html 改排版改得多,当然红色部分要注意下,用得较多 ------- ...
- Android Studio accelerator key(shortcut)& Basic knowledge
shift + F6 重构(选文件,ok->下面的控制台,do refactor option + return 快速修复 Activity@Extra() Intent: @FragmentA ...
- js 实时监听input中值变化
注意:用到了jquery需要引入jquery.min.js. 需求: 1.每个地方需要分别打分,总分为100; 2.第一个打分总分为40; 3.第二个打分总分为60. 注意:需要判断null.&quo ...
- Linux 添加完硬盘后,如何挂载和分区、以及其他的分区不足,如何从新的硬盘上挂载借用
挂载好新硬盘后输入fdisk -l命令看当前磁盘信息 可以看到除了当前的第一块硬盘外还有一块sdb的第二块硬盘,然后用fdisk /dev/sdb 进行分区 进入fdisk命令,输入h可以看到该命令的 ...
- 游戏的套路你知道吗? H5 Canvas刮刮乐
玩游戏的人 很多时候都会遇到翻牌子 开宝箱. 总有人傻傻的在哪里还纠结很久到底点哪一个! 纠结 指不定翻哪一个会多一点,你明明看到那个卡片的奖项多 . 那我就告诉你好了 其实很多时候在你点开那个 ...
- iOS开发常用校验
一.身份证号码校验 + (BOOL)cheakIdentityCard: (NSString *)value { value = [value stringByTrimmingCharactersIn ...
- mysql 事件
经常要周期性的执行某一个命令或者SQL语句.mysql事件,mysql的版本是5.1以上. 首先要查看事件是否开启了, SHOW VARIABLES LIKE 'event_scheduler'; S ...
- python之面向对象
首先我们应该知道,python在设计之初就已经是一门面向对象的语言,所以说python中创建一个类和对象是很容易的. 面向对象的技术简介 类(class):用来描述具有相同的属性和方法的对象的集合.它 ...
- 用ILSpy查看Session.SessionID的生成算法
缘由 asp.net Session在InProc模式下,容易丢失,经常需要重新登录,且不支持分布式共享. 所以在研究Redis实现原生的Session,本来想用GUID作为key存入cookie,又 ...