我试图开发一种登录表单,该表单从服务器检查用户名和密码,但是当我试图执行代码时,会发生“未初始化连接属性"的异常. [英] I'm triying to devleop a login form, which check username and password from server but when I'm triying to execute code an exception is occured "Connection property is not initialized".

查看:156
本文介绍了我试图开发一种登录表单,该表单从服务器检查用户名和密码,但是当我试图执行代码时,会发生“未初始化连接属性"的异常.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string username = textBox1.Text;
            string pass = textBox2.Text;
            cmd = new SqlCommand("select * from the user_login where username ='" + username + "'", con);
            dr = cmd.ExecuteReader();
            while(dr.Read())
            {
                if((username==dr[0].ToString())&&(pass==dr[1].ToString()))
                {
                    string acc=dr[2].ToString();
                    Class1.access=acc;
                    Form2 mf = new Form2();
                    mf.Show();
                }
                else
                {
                MessageBox.Show("Unauthorized access");
                }
                con.Close();

推荐答案

将密码存储为纯文本是不安全的做法.您应该使用带有盐的单向哈希来存储密码.请编辑您的帖子以添加例外详细信息.
Storing passwords as plain text is bad security practice. You should store passwords using a one-way hash with a salt. Please edit your post to add the exception details.


您也可以发布连接创建代码吗?
Could you post the connection creation code as well?


这篇关于我试图开发一种登录表单,该表单从服务器检查用户名和密码,但是当我试图执行代码时,会发生“未初始化连接属性"的异常.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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