This commit is contained in:
aitzol 2023-11-16 05:35:57 +01:00
parent d477a40859
commit e6c8abe026
3 changed files with 62 additions and 27 deletions

View File

@ -15,17 +15,35 @@
<main>
<h1>2FA</h1>
<form name="editEmailForm" method="post" action="/user">
% if data['secureAuth'] == True:
<form name="editEmailForm" method="post" action="/user">
<label for="2fa">2FA</label>
<input id="2fa" name="2fa" type="text" value="" required>
<label for="2fa">2FA</label>
<input id="2fa" name="2fa" type="text" value="" required>
<div class="form-buttons">
<a href="/user"><button class="green" type="button">{{ str['back'] }}</button></a>
<button class="green" type="submit">{{ str['update'] }}</button>
</div>
<div class="form-buttons">
<a href="/user"><button class="green" type="button">{{ str['back'] }}</button></a>
<button class="green" type="submit">Disable</button>
</div>
</form>
</form>
% else:
<form name="editEmailForm" method="post" action="/user">
<label for="2fa">2FA</label>
<input id="2fa" name="2fa" type="text" value="" required>
<div class="form-buttons">
<a href="/user"><button class="green" type="button">{{ str['back'] }}</button></a>
<button class="green" type="submit">Enable</button>
</div>
</form>
%end
%for type, text, animation in get('alerts', []):
<div class="alerts {{ animation }}">

29
libs/gen2fa.py Normal file
View File

@ -0,0 +1,29 @@
from onetimepass import valid_totp
from secrets import choice
def generate_secret(): # Function to return a random string with length 16.
secret = ''
while len(secret) < 16:
secret += choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
return secret
secret = generate_secret()
print('Enter the following secret in your authenticator app: ', secret)
print("""
Instructions for saving this secret it Google Authenticator:
1. Open Google Authenticator.
2. Click plus icon at the right bottom.
3. Click Enter a setup key.
4. Enter an Account name of your choice and enter the secret provided above.
5. Click Add.
""")
while True:
otp = int(input('Please enter the otp generated by your authenticator app: '))
authenticated = valid_totp(otp, secret)
if authenticated:
print('Correct otp, Authenticated!')
elif not authenticated:
print('Wrong otp, please try again.')

View File

@ -50,34 +50,22 @@
<div class="grid-item">
<a href="/change_pwd">{{ str['edit'] }}</a>
</div>
<!--
<div class="grid-item">
<div class="account">
<h5>2FA</h5>
<p>Bi urratseko autentifikazioa {{data['secureAuth']}}</p>
</div>
</div>
<div class="grid-item">
<input type="checkbox" id="2fa" name="2fa" value="2fa" {{!'checked="checked"' if data['secureAuth'] == True else ""}} >
</div>
-->
<!--
<div class="grid-item">
<a href="/_2fa">{{'Desgaitu' if data['secureAuth'] == True else "Gaitu"}}</a>
</div>
-->
<!-- 2FA -->
<div class="grid-item">
<div class="account">
<h5>2FA</h5>
<p>Bi urratseko autentifikazioa {{data['secureAuth']}}</p>
<p>Bi urratseko autentifikazioa</p>
</div>
</div>
<div class="grid-item">
<!--<a href="/_2fa">{{'Kendu' if data['secureAuth'] == True else "Ezarri"}}</a>-->
<a href="/_2fa">{{"<i class='ri-toogle-fill'></i>" if data['secureAuth'] == True else "<i class='ri-toggle-line'></i>"}}</a>
<!-- <a href="/_2fa"><i class="ri-toggle-fill"></i></a> -->
% if data['secureAuth'] == True:
<a href="/_2fa"><i class='ri-toggle-fill'></i></a>
% else:
<a href="/_2fa"><i class='ri-toggle-line'></i></a>
%end
</div>
<div class="grid-item">