Commit cc245056 authored by Wen Wei Li's avatar Wen Wei Li

otp check

parent c00d218d
*.bak *.bak
storage/ storage/
__pycache__ __pycache__
*.pyc
...@@ -76,7 +76,8 @@ def wifi_pass(ssid): ...@@ -76,7 +76,8 @@ def wifi_pass(ssid):
if(cell is not None): if(cell is not None):
return render_template('index.html', data=ssid,isEnc=is_encrypted(cell)) return render_template('index.html', data=ssid,isEnc=is_encrypted(cell))
else: else:
return redirect(url_for('index')) return render_template('index.html', data="None",isEnc=True)
#return redirect(url_for('index'))
@app.route('/wifi_select/', methods=['GET']) @app.route('/wifi_select/', methods=['GET'])
def pass_without_ssid(): def pass_without_ssid():
...@@ -112,6 +113,18 @@ def pin_store(): ...@@ -112,6 +113,18 @@ def pin_store():
@app.route("/main_page", methods=['GET']) @app.route("/main_page", methods=['GET'])
def main_page(): def main_page():
return render_template("main_page.html") return render_template("main_page.html")
@app.route("/<string:otp>", methods=['GET'])
def otp(otp):
return render_template("otp.html", data=otp)
@app.route("/otp_check", methods=['POST'])
def check_otp():
otp_type = request.form.get('type')
otp = request.form.get('pin')
print(otp_type, otp)
return redirect(url_for('index'))
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True) app.run(host='0.0.0.0', port=8080, debug=True)
import pyotp
import base64
class otp_utils:
def __init__(self,secret):
self.otp_checker = pyotp.TOTP(base64.b32encode(secret.encode('utf-8')), interval=60, digits=6)
def check(self,totp):
return self.otp_checker.verify(totp);
def generate(self):
return self.otp_checker.now()
flask flask
flask-bootstrap flask-bootstrap
sqlite3 sqlite3
pyotp
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
} }
.scrollbar{ .scrollbar{
position:relative; position:relative;
height: 300px; height: 200px;
overflow: auto; overflow: auto;
} }
input { input {
......
...@@ -29,26 +29,26 @@ ...@@ -29,26 +29,26 @@
{% endblock head %} {% endblock head %}
{% block content%} {% block content%}
<body class="bg-light m-5"> <body class="bg-light ml-1 mr-1">
<div> <div>
<p style="visibility:hidden" id="ssid">{{data}}</p> <p style="visibility:hidden" id="ssid">{{data}}</p>
<h2 class="text-muted text-center m-5">Wifi Password</h2> <button type="submit" class="btn btn-primary btn-lg btn-font" id="prev" >Previous</button>
<h2 class="text-muted text-center">Wifi Password</h2>
<center> <center>
{% if isEnc is sameas true%} {% if isEnc is sameas true%}
<div class="row align-items-center m-5 col-8"> <div class="row align-items-center m-1 col-8">
<div class="col-10 inline "> <div class="col-10 inline ">
<input type="password" class="form-control input btn-font" id="wifi-password" <input type="password" class="form-control input btn-font" id="wifi-password"
placeholder="Tap on the virtual keyboard to start"> placeholder="Tap on the virtual keyboard to start">
</div> </div>
{% endif%} <div class="col-2 inline">
<button type="submit" class="btn btn-primary btn-lg btn-font" id="conn" >Connect</button>
</div> </div>
<div class="container m-5"> {% endif%}
<button type="submit" class="btn btn-primary btn-danger btn-lg pull-left btn-font" id="prev" >Previous</button>
<button type="submit" class="btn btn-primary btn-danger btn-lg pull-right btn-font" id="conn" >Connect</button>
</div> </div>
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col m-5 inline"> <div class="col inline">
<div class="simple-keyboard" id="keyboard" style="visibility: visible"></div> <div class="simple-keyboard" id="keyboard" style="visibility: hidden"></div>
</div> </div>
</div> </div>
</center> </center>
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
<center> <center>
<button type="submit" id="pin_setup" class="btn btn-primary btn-danger btn-lg btn-font">Pincode Setup</button> <button type="submit" id="pin_setup" class="btn btn-primary btn-danger btn-lg btn-font">Pincode Setup</button>
<button type="submit" id="setting" class="btn btn-primary btn-danger btn-lg btn-font">Preference</button> <button type="submit" id="setting" class="btn btn-primary btn-danger btn-lg btn-font">Preference</button>
<button type="submit" id="totp" class="btn btn-primary btn-danger btn-lg btn-font">Input TOTP</button>
<button type="submit" id="otp" class="btn btn-primary btn-danger btn-lg btn-font">Input OTP</button>
</center> </center>
</div> </div>
{% block footer %} {% block footer %}
...@@ -32,6 +34,12 @@ ...@@ -32,6 +34,12 @@
$("#pin_setup").click(function(){ $("#pin_setup").click(function(){
window.location.href="http://localhost:8080/pin_setup"; window.location.href="http://localhost:8080/pin_setup";
}); });
$("#totp").click(function(){
window.location.href="http://localhost:8080/totp";
});
$("#otp").click(function(){
window.location.href="http://localhost:8080/otp";
});
</script> </script>
{% endblock scripts %} {% endblock scripts %}
{% endblock content %} {% endblock content %}
{% extends "bootstrap/base.html" %}
{% block head %}
{{super()}}
<!-- bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<!-- keyboard css-->
<link rel="stylesheet" href="{{url_for('static',filename='css/keyboard.css')}}">
<link rel="stylesheet" href="{{url_for('static',filename='css/main.css')}}">
<script>
$(document).ready(function () {
document.getElementById("keyboard").style.visibility = 'visible';
});
</script>
{% endblock head %}
{% block content%}
<body class="container mx-auto bg-light m-2">
<h2 class="text-muted text-center m-5">{{data}} Input</h2>
<center>
<div class="row col mx-auto m-2 col-8">
<div class="col-sm">
{% for i in range(6) %}
<input type="password" class="form-control input float-left col-sm-2 text-center input_margin btn-font" id="slot-{{loop.index}}" disabled="true" maxlength="1">
{% endfor %}
</div>
<div class="col-2 inline">
<button type="submit" class="btn btn-primary btn-font" id="setup" >Confirm</button>
</div>
</div>
<div class="row align-items-center">
<div class="col m-2 inline">
<div class="simple-keyboard" id="keyboard" style="visibility: hidden"></div>
</div>
</div>
</center>
<script src="{{url_for('static', filename='js/keyboard.min.js')}}"></script>
<script src="{{url_for('static', filename='js/pincode.js')}}"></script>
<script>
$('#setup') .click(function(){
if( pin_code.length == 6 ){
console.log(pin_code);
pin = pin_code.join('');
data="type={{data}}&pin="+pin
$.ajax({
type:"POST",
url:"http://localhost:8080/otp_check",
data:data,
success:function(data, status){
alert("PIN CODE SETUP SUCCESS");
window.location.href="http://localhost:8080/main_page";
},
error:function(data, status){
alert("PIN CODE SETUP FAILED")
}
});
}else{
alert('PINCODE LENGTH MUST BE 6');
}
})
</script>
<!-- keyboard js-->
</body>
{% block footer %}
<footer class="footer" >
<div class="footer navbar-fixed-bottom text-center">
<p class="text-muted">&copy; NTUST PRLAB</p>
</div>
</footer>
{% endblock footer %}
{% endblock %}
...@@ -31,21 +31,21 @@ ...@@ -31,21 +31,21 @@
{% endblock head %} {% endblock head %}
{% block content%} {% block content%}
<body class="container mx-auto bg-light m-5"> <body class="container mx-auto bg-light m-2">
<h2 class="text-muted text-center m-5">PinCode Setup</h2> <h2 class="text-muted text-center m-5">PinCode Setup</h2>
<center> <center>
<div class="row col mx-auto m-5 col-8"> <div class="row col mx-auto m-2 col-8">
<div class="col-sm"> <div class="col-sm">
{% for i in range(6) %} {% for i in range(6) %}
<input type="password" class="form-control input float-left col-sm-1 text-center input_margin" id="slot-{{loop.index}}" disabled="true" maxlength="1"> <input type="password" class="form-control input float-left col-sm-2 text-center input_margin btn-font" id="slot-{{loop.index}}" disabled="true" maxlength="1">
{% endfor %} {% endfor %}
</div> </div>
<div class="col-2 inline"> <div class="col-2 inline">
<button type="submit" class="btn btn-primary" id="setup" style="height:50px">Confirm</button> <button type="submit" class="btn btn-primary btn-font" id="setup" >Confirm</button>
</div> </div>
</div> </div>
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col m-5 inline"> <div class="col m-2 inline">
<div class="simple-keyboard" id="keyboard" style="visibility: hidden"></div> <div class="simple-keyboard" id="keyboard" style="visibility: hidden"></div>
</div> </div>
</div> </div>
......
from otp import *
otper = otp_utils('rewrewr')
otp = otper.generate()
print("otp is {}".format(otp))
ret = otper.check(otp)
print("Check OTP {} is {}".format(otp, ret))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment