Hướng dẫn login and signup code in python - đăng nhập và mã đăng ký trong python

Đây là chương trình đầu tiên của tôi mà tôi đã tự viết. Có điều gì tôi có thể cải thiện?

Có một vài điều vẫn cần được thêm vào, chẳng hạn như:

  • Xác nhận mật khẩu trong khi đăng ký
  • Thêm một cách để lấy mật khẩu bị lãng quên bằng ID email

Nhưng chức năng của nó là hoàn thành tối thiểu. Có điều gì mà các chuyên gia thấy rằng tôi có thể cải thiện hoặc thay đổi trong chương trình này không?

Tập tin chính

import Functions

start = ""

while start == "" :
    start = input("Type S to Create a Account and Type L to login into your Account:  ")
    Username_List = Functions.username_list()
    if start == "S" or start == "s":
        username = input("Enter a Username: ")
        for user in Username_List:
            while user == username:
                username = input("Username Exists, Try Again: ")
        password = input("Enter a Password: ")
        email_adress = input("Enter Email ID: ")
        Functions.sign_up(username,password,email_adress)
        start = ""

    elif start == "L" or start == "l":
        login_username = input("Enter Your Username: ")
        while login_username not in Username_List:
            print('Username Does not Exist.')
            user_input = input("Type R to retry and X to exit: ")
            if user_input == "r" or user_input == "R":
                login_username = input("Enter Your Username: ")
            if user_input == "x" or user_input == "X":
                break
        if login_username not in Username_List:
            print("Invalid Session \n\n")
            start = ""
        else:
            no = Username_List.index(login_username)
            password = input("Enter a Password: ")
            Functions.extract_matrix(login_username,password,no)
            start = ""

    else:
        print("Invalid Session \n\n")
        start = ""

Functions.py

import csv
def sign_up(username,password,email):

    filename = "signup_info.csv"
    data = [[username,password,email]]
    # writing to csv file
    with open(filename, 'a', newline='') as csvfile:
        # creating a csv dict writer object
        writer = csv.writer(csvfile)

        # writing data rows
        writer.writerows(data)

def username_list():
    username_list=[]
    with open('signup_info.csv','r') as f:
        for line in f :
            username_list.append(line.split(',')[0])
        return username_list

def extract_matrix(username,password,no):
    password_list = []
    email_list = []
    username_list = []
    with open('signup_info.csv','r') as f:
            for line in f:
                password_list.append(line.split(',')[1])
            for line in f:
                email_list.append(line.split(',')[2])
            for line in f:
                username_list.append(line.split(',')[0])

    data_password = password_list[no]
    while password != data_password:
        print('Incorrect Password')
        user_input = input ("Type R to retry and X to exit: ")
        if user_input == "r" or user_input == "R":
            password = input("Enter Password: ")
        if user_input == "x" or user_input == "X":
            break
    if password == data_password:
       print("Login Successful")
    else:
        print("Invalid Session \n\n")

-1

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi muốn có một chương trình cho phép người dùng tạo tài khoản nếu họ không có, nhưng nếu họ làm điều đó cho phép họ đăng nhập và kiểm tra tên người dùng và mật khẩu với các tên họ khi họ tạo tài khoản. Mã này hoạt động để đăng ký, nhưng không phải cho phần đăng nhập / kiểm tra nếu người đó đã tạo tài khoản.

import os.path
if os.path.exists("username"):
    login()
    else:
        make_account()

def make_account

filename = ("username");
with open (filename, "w") as f:
  f.write (input("Enter a username: "));

filename = ("password");
with open (filename, "w") as f:
  f.write (input("Enter a password: "));


def login
username = input("Enter your username: ")
password = input("Enter your password: ")
check()

def check
if username == open("username").read(): and
passsword == open("password").read():
    print("Successful login")
else:
    print('Incorrect')

hỏi ngày 31 tháng 7 năm 2017 lúc 15:05Jul 31, 2017 at 15:05

4

Thử cái này:

import os.path
if os.path.exists("username"):
    login()
else:
    make_account()

def make_account():

    filename = ("username");
    with open (filename, "w") as f:
      f.write (input("Enter a username: "));

    filename = ("password");
    with open (filename, "w") as f:
      f.write (input("Enter a password: "));


def login():
    username = input("Enter your username: ")
    password = input("Enter your password: ")
    check()

def check():
    if username == open("username").read() and passsword == open("password").read():
        print("Successful login")
    else:
        print('Incorrect')

Đã trả lời ngày 31 tháng 7 năm 2017 lúc 15:19Jul 31, 2017 at 15:19

Hướng dẫn login and signup code in python - đăng nhập và mã đăng ký trong python

1

import os.path


def login():
    def make_account():

        filename = "username"
        with open(filename, "w") as f:
            f.write(input("Enter a username: "))

        filename = "password"
        with open(filename, "w") as f:
            f.write(input("Enter a password: "))

    def login():
        def check():
            if username == open("username").read() and\
                    password == open("password").read():
                print("Successful login")
            else:
                print('Incorrect')

        username = input("Enter your username: ")
        password = input("Enter your password: ")
        check()

    if os.path.exists("username"):
        login()
    else:
        make_account()

Hướng dẫn login and signup code in python - đăng nhập và mã đăng ký trong python

S.B

9.3617 Huy hiệu vàng19 Huy hiệu bạc40 Huy hiệu đồng7 gold badges19 silver badges40 bronze badges

Đã trả lời ngày 28 tháng 3 lúc 1:36Mar 28 at 1:36

1

Làm cách nào để tạo một trang đăng nhập và đăng ký trong Python?

DEF register_user (): # Nhận tên người dùng và mật khẩu ..
username_info = tên người dùng. lấy() ... .
# Mở tệp trong chế độ ghi. File = Open (username_info, "w").
# Viết tên người dùng và thông tin mật khẩu vào tệp. tập tin. ....
tập tin. gần() ... .
password_entry. ....
Nhãn (Đăng ký_screen, Text = "Thành công đăng ký", fg = "Green", font = ("calibri", 11)) ..

Đăng ký đăng nhập trong Python là gì?

Đăng nhập và đăng ký Python là một mô -đun được phát triển để cung cấp xác thực người dùng cơ bản trong Python.Đó là một cấu trúc rất xương trần vì lý do các nhà phát triển khác có thể truy cập nội dung của các tệp nguồn và nhìn xung quanh để tìm hiểu cách cấu trúc các mô-đun hoặc dự án của riêng họ.a module developed to provide basic user authentication in Python. It is a very bare-bones structure for the reason that other developers can access the contents of the source files and look around in order to learn how to structure their own modules or projects.

Làm cách nào để đăng nhập người dùng bằng Python?

Phương thức GetLogin () của thư viện hệ điều hành được sử dụng để lấy tên người dùng hiện tại ...
Cú pháp: os.getLogin () Để sử dụng chức năng này, chúng tôi cần nhập thư viện hệ điều hành trước ..
Cú pháp: OS.Path.ExpandUser ().
Cú pháp: OS.Envir.get (tên người dùng của người dùng) ....
Cú pháp: getpass.getUser ().
Cú pháp: getpwuid (os.getuid ()) [0].

Làm cách nào để đăng nhập vào một trang web bằng Python?

Tìm URL của trang đăng nhập mà bạn muốn đăng nhập. Cung cấp vị trí Trình điều khiển Chrome có thể thực thi cho Selenium WebDriver để truy cập trình duyệt Chrome.Cuối cùng, hãy tìm tên hoặc ID hoặc bộ chọn CSS hoặc CSS của tên người dùng và mật khẩu bằng cách nhấp chuột phải kiểm tra tên người dùng và mật khẩu.