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

style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, PHP CS Fixer, Prettier, RuboCop, Rustfmt, Scalafmt, StandardJS, StandardRB and Yapf #15

Merged
merged 1 commit into from
Apr 12, 2024
Merged
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
15 changes: 10 additions & 5 deletions func/user_auth.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import random
import string

from twilio.rest import Client


def generate_salt():
"""Generates a random salt for password hashing."""
return ''.join(random.choices(string.ascii_letters + string.digits, k=16))
return "".join(random.choices(string.ascii_letters + string.digits, k=16))


def hash_password(password, salt):
"""Hashes a password with a salt using bcrypt."""
return bcrypt.hashpw(password.encode() + salt.encode(), bcrypt.gensalt())


def register(username, password):
"""Registers a new user with the given username and password."""
# Generate a random salt for the password
Expand All @@ -22,18 +26,17 @@ def register(username, password):
# ...

# Generate a random MFA code
mfa_code = ''.join(random.choices(string.digits, k=6))
mfa_code = "".join(random.choices(string.digits, k=6))

# Send the MFA code to the user's phone
client = Client(account_sid, auth_token)
message = client.messages.create(
body=f"Your MFA code is {mfa_code}",
from_='+1234567890',
to='+0987654321'
body=f"Your MFA code is {mfa_code}", from_="+1234567890", to="+0987654321"
)

return True


def login(username, password, mfa_code):
"""Logs in a user with the given username, password, and MFA code."""
# Retrieve the user's salt, hashed password, and MFA secret from the database
Expand All @@ -56,12 +59,14 @@ def login(username, password, mfa_code):
# Password is incorrect
return False


def logout():
"""Logs out the current user."""
# Clear the user's session or authentication token
# ...
return True


def check_mfa_code(code, secret):
"""Verifies an MFA code using the Totp algorithm."""
return totp.verify(code, secret)
Loading