用户登录时在标签中显示名字和姓氏 [英] Display firstname and lastname in label when user logs in

查看:171
本文介绍了用户登录时在标签中显示名字和姓氏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录窗口,当用户输入用户名和密码后,当用户按下登录按钮时,我希望它以两个标签显示用户的姓名和姓氏,



问题是用户的值为null,为什么?



这个代码我在我的登录按钮

  private   void  LogIn()
{


var db = new DigitalFakturaDBEntities1();
var s =(来自 p in db.Users
其中 p.Username ==TextBoxÚsernameLoginIN.Text&& p.Password == TextBoxPasswordLogin.Text
< span class =code-sdkkeyword> select p);

if (s.Any())

{
var user = new Users();
user.Firstname = LabelFirstnameDisplay.Text;
}
LabelErrorLogIn.Visible = false ;
}

解决方案

为什么你从我的数据库中取出我假设的用户列表,然后忽略它你检查过那里有没有?

  if (s.Any())

检查是否有任何用户匹配,但您创建了一个与其中任何用户无关的空用户,并将其firstname设置为现有标签,该标签与您刚查找的用户完全没有任何关系。 。

也许您想从 s 开始,并使用该信息作为识别用户的基础?



请不要这样做!切勿以明文形式存储密码 - 这是一个主要的安全风险。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]


I have a login windows where users enters username and password after that when the user press the Login button i want it to display fistname and lastname och the user in a two labels,

The problem is that the value of the user get null, why?

This code i have in my login Button

private void LogIn()
        {
            
                
                var db = new DigitalFakturaDBEntities1();
                var s = (from p in db.Users
                    where p.Username == TextBoxÚsernameLoginIN.Text && p.Password == TextBoxPasswordLogin.Text
                    select p);
                
                if (s.Any())

                {
                    var user = new Users();
                    user.Firstname = LabelFirstnameDisplay.Text;
                }
                LabelErrorLogIn.Visible = false;
            }

解决方案

Why are you fetching what I assume is a list of users from your DB, and then ignoring it when you have checked if there are any in there?

if (s.Any())

Checks if any users match, but you then create an empty user that is unrelated to any of them, and set it's firstname to an existing label that has nothing at all to do with the users you just looked for...
Perhaps you want to start with s and use that information as a basis for identifying your users?

And please, don't do it like that! Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]


这篇关于用户登录时在标签中显示名字和姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆