简体   繁体   English

用户登录后如何存储/打印用户 ID/用户名?

[英]How do I store/print userid/username after user logged in?

I want to store userid in a variable after the users logged in and I am not sure how to do that.我想在用户登录后将 userid 存储在一个变量中,但我不知道该怎么做。 I used getpass.getuser() , but it gives me the username from my computer system.我使用了getpass.getuser() ,但它给了我计算机系统中的用户名。 Does session work in tkinter?会话在 tkinter 中工作吗? Can somebody give me an idea how should I approach this?有人可以给我一个想法我应该如何处理这个问题吗? The user id is increased automatically for new user新用户的用户 ID 会自动增加

class data:
    def checks(name, password):
        conn = sqlite3.connect('login.db')
        cur = conn.cursor()
        if cur.execute('SELECT * FROM user WHERE name = ? AND password = ?', (name, password)):
            if cur.fetchone():
                window.destroy()
                login_backend.back()
            else:
                messagebox.showinfo('error', 'Username and password is wrong')
def login_student(self):
          if len(self.namee.get()) == 0 or len(self.password1e.get()) == 0:
                     messagebox.showinfo("ERROR", "Mandatory Field is empty")
          else:
            data.checks(self.namee_text.get(), self.password1e_text.get())

Do you want to get a password and user name on the command line?您想在命令行上获取密码和用户名吗? If so, the secure way to do this is with getpass.getpass().如果是这样,执行此操作的安全方法是使用 getpass.getpass()。 This will prompt the user.这将提示用户。 getpass.getuser(), as you discovered, is for the system user.正如您所发现的,getpass.getuser() 是针对系统用户的。

https://docs.python.org/2/library/getpass.html https://docs.python.org/2/library/getpass.html

You don't want to print the password on the command line because of the security risk.由于安全风险,您不想在命令行上打印密码。 Generally, you want to consume the sensitive credentials only as long as needed to access the resource.通常,您只想在访问资源所需的时间内使用敏感凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM