-
Notifications
You must be signed in to change notification settings - Fork 317
Closed
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues, especially the pinned issues.
Exception report
-----------------------------------------------------------------------
Last 5 Keys:
& Space " C :
Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: left
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)Screenshot
need correction
Environment data
import bcrypt
import pyotp
import sqlite3
import smtplib
import random
import ctypes
from getpass import getpass
from email.message import EmailMessage
# Load Windows Biometric Framework (WBF)
winbio = ctypes.windll.winbio
# Database setup
def init_db():
with sqlite3.connect("users.db") as conn:
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS users (
username TEXT PRIMARY KEY,
first_name TEXT,
last_name TEXT,
phone_number TEXT,
password_hash TEXT,
otp_secret TEXT,
email TEXT)''')
conn.commit()
# Hash password
def hash_password(password):
return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
# Verify password
def verify_password(password, hashed):
return bcrypt.checkpw(password.encode(), hashed.encode())
# Generate OTP secret
def generate_otp_secret():
return pyotp.random_base32()
# Send OTP via email
def send_otp_email(email, otp):
sender_email = "[email protected]"
sender_password = "your_app_password"
msg = EmailMessage()
msg.set_content(f"Your OTP is: {otp}")
msg["Subject"] = "Your OTP Code"
msg["From"] = sender_email
msg["To"] = email
try:
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
server.login(sender_email, sender_password)
server.send_message(msg)
print("OTP sent successfully to email!")
except Exception as e:
print("Error sending OTP via email:", e)
# Send OTP via phone (placeholder function)
def send_otp_phone(phone_number, otp):
print(f"OTP {otp} sent to phone number {phone_number} (simulation).")
# Fingerprint Authentication using Windows Biometric Framework
def fingerprint_auth():
try:
result = winbio.WinBioVerify()
return result == 0 # 0 indicates success
except Exception as e:
print("Fingerprint authentication failed:", e)
return False
# User Registration
def register():
username = input("Enter username: ")
first_name = input("Enter first name: ")
last_name = input("Enter last name: ")
phone_number = input("Enter phone number: ")
password = getpass("Enter password: ")
email = input("Enter email: ")
otp_secret = generate_otp_secret()
password_hash = hash_password(password)
try:
with sqlite3.connect("users.db") as conn:
cursor = conn.cursor()
cursor.execute("INSERT INTO users (username, first_name, last_name, phone_number, password_hash, otp_secret, email) VALUES (?, ?, ?, ?, ?, ?, ?)",
(username, first_name, last_name, phone_number, password_hash, otp_secret, email))
conn.commit()
print("User registered successfully!")
except sqlite3.IntegrityError:
print("Username already exists!")
# User Login
def login():
username = input("Enter username: ")
password = getpass("Enter password: ")
with sqlite3.connect("users.db") as conn:
cursor = conn.cursor()
cursor.execute("SELECT password_hash, otp_secret, email, phone_number FROM users WHERE username = ?", (username,))
user = cursor.fetchone()
if not user:
print("User not found!")
return
password_hash, otp_secret, email, phone_number = user
if not verify_password(password, password_hash):
print("Invalid password!")
return
# OTP Verification
otp = random.randint(100000, 999999)
otp_choice = input("Do you want to receive OTP via (1) Email or (2) Phone? ")
if otp_choice == "1":
send_otp_email(email, otp)
elif otp_choice == "2":
send_otp_phone(phone_number, otp)
else:
print("Invalid choice! Defaulting to email.")
send_otp_email(email, otp)
user_otp = input("Enter OTP received: ")
if str(user_otp) != str(otp):
print("Invalid OTP!")
return
# Fingerprint Authentication
if not fingerprint_auth():
print("Fingerprint authentication failed!")
return
print("Login successful!")
# Main Menu
def main():
init_db()
while True:
print("\n1. Register\n2. Login\n3. Exit")
choice = input("Enter choice: ")
if choice == "1":
register()
elif choice == "2":
login()
elif choice == "3":
break
else:
print("Invalid choice!")
if __name__ == "__main__":
main()Steps to reproduce
python
Expected behavior
error code
Actual behavior
not running
Metadata
Metadata
Assignees
Labels
No labels