在Web应用程序中使用用户的浏览器指纹进行身份验证。
bfa的Python项目详细描述
浏览器指纹验证
此软件包允许您获取并使用Web应用程序的用户浏览器指纹作为身份验证程序。
行动中
如果您想自己测试这个方法,请检查我们的demo site。
内容
安装
您可以通过以下方式安装软件包:
pip install bfa
用法
目前提供了django和flask支持,未来计划增加其他框架。
django
将'bfa'
添加到settings.py中的INSTALLED_APPS
列表中:
INSTALLED_APPS=[...'bfa']
您可以通过以下方式获取用户指纹:
bfa.fingerprint.get(request)
在模板内粘贴
<form></form>
:{% load bfa %}{% fingerprint_input %}
例如:
login.html
... <formmethod="post"> {% csrf_token %} <inputname="username"> {% load bfa %} {% fingerprint_input %} <buttontype="submit">Log in</button></form> ...
views.py
importbfafromdjango.httpimportHttpResponsefromdjango.shortcutsimportrender...deflogin(request):ifrequest.method=='POST':# Getting a usernameusername=request.POST.get('username')# Getting a fingerprinttry:fp=bfa.fingerprint.get(request)except(ConnectionError,ValueError):returnHttpResponse("Can't get fingerprint")# Here is the part where you process the # username and fingerprint, according to the database...returnHttpResponse("You're logged in")returnrender(request,'login.html')...
烧瓶
将bfa上下文处理器添加到app.py:
...importbfafromflaskimportFlaskapp=Flask(__name__)@app.context_processor# Don't change name of this functiondefbfa_flask():returnbfa.templatetags.bfa.fingerprint_input()...
您可以通过以下方式获取用户指纹:
bfa.fingerprint.get(request)
在模板内粘贴
<form></form>
:{{ fingerprint_input }}
例如:
login.html
... <formmethod="post"><inputname="username"> {{ fingerprint_input }} <buttontype="submit">Log in</button></form> ...
app.py
importbfafromflaskimportFlask,requestapp=Flask(__name__)...@app.route('/login/',methods=['POST','GET'])deflogin():ifrequest.method=='POST':# Getting a usernameusername=request.form['username']# Getting a fingerprinttry:fp=bfa.fingerprint.get(request)except(ConnectionError,ValueError):return"Can't get fingerprint"# Here is the part where you process the # username and fingerprint, according to the database...return"You're logged in"else:return"Login page"...
也
您可以通过以下方式对指纹进行盐渍:
bfa.fingerprint.get(request, use_salt=True)
例如:
views.py
importbfafromdjango.httpimportHttpResponsefromdjango.shortcutsimportrender...deflogin(request):ifrequest.method=='POST':# Getting a usernameusername=request.POST.get('username')# Getting a fingerprinttry:fp_data=bfa.fingerprint.get(request,use_salt=True)except(ConnectionError,ValueError):returnHttpResponse("Can't get fingerprint")fp=fp_data['fp']salt=fp_data['salt']# Here is the part where you process the # username, fingerprint and salt, according to the database...returnHttpResponse("You're logged in")returnrender(request,'login.html')...
使用
此项目使用:
支持的Python
bfa只处理python>;=3.5。
许可证
此项目受Apache2.0许可。