Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nt password #59

Open
wants to merge 1 commit into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VPNAccount(db.Model):
def __init__(self, username, value, is_expiration=False):
self.username = username
self.value = value
self.attribute = 'Expiration' if is_expiration else 'Cleartext-Password'
self.attribute = 'Expiration' if is_expiration else 'NT-Password'
self.op = ':='

def save(self):
Expand All @@ -58,7 +58,7 @@ def save(self):

@classmethod
def get_account_by_email(cls, email):
return cls.query.filter_by(username=email).filter_by(attribute='Cleartext-Password').first()
return cls.query.filter_by(username=email).filter_by(attribute='NT-Password').first()

@classmethod
def get_expiration_by_email(cls, email):
Expand All @@ -68,7 +68,7 @@ def get_expiration_by_email(cls, email):
def add(cls, email, password, expiration):
account = cls.get_account_by_email(email)
if not account:
account = cls(email, password)
account = cls(email, hash_nt_passwd(password.encode('utf-16le')))
account.save()
if not Group.get_group_by_email(email):
group = Group(email)
Expand Down Expand Up @@ -107,7 +107,7 @@ def changepass(cls, email, newpass):
if not account:
raise Exception('account not found')
else:
account.value = newpass
account.value = hash_nt_passwd(newpass.encode('utf-16le'))
account.save()


Expand Down Expand Up @@ -186,6 +186,10 @@ def get_rejected(cls):
def get_users(cls):
return cls.query.filter(db.or_(cls.status == 'pass', cls.status == 'banned')).order_by(cls.id).all()

def vpnpassword_invisible(self):
self.vpnpassword = "<secure>"
self.save()

def pass_apply(self, is_long=False):
self.status = 'pass'
self.expiration = next_semester_end()
Expand Down
5 changes: 5 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import random
import string
import datetime
import hashlib
from base64 import b64encode

def hash_nt_passwd(passwd_utf16le):
nt_password = b64encode(hashlib.new('md4', passwd_utf16le).digest())
return nt_password

def random_string(N):
return ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(N))
Expand Down
4 changes: 4 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def login():
flash('Email not confirmed. Please recover your account at the bottom of this page.', 'error')
else:
login_user(user)
if user.status == 'pass':
user.vpnpassword_invisible()
return redirect(url_for('index'))
return render_template('login.html', form=form)

Expand Down Expand Up @@ -146,6 +148,8 @@ def cancel():
@app.route('/logout/', methods=['POST'])
@login_required
def logout():
if current_user.status == 'pass':
current_user.vpnpassword_invisible()
logout_user()
return redirect(url_for('login'))

Expand Down