解决登录表单问题 [英] Solution of Login Form problem

查看:103
本文介绍了解决登录表单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表单,我想检查登录表单.它包括用户名和密码.如何使用sqlser数据库检查用户名和密码.我需要代码来解决这个问题.任何人都可以帮助我.

I have a login form and i want to check the login form. It include username and password. How can i check username and password with sqlser database. I need code to solve this problem. Anyone can help me.

推荐答案

我认为最好从
开始 此处 [
I think it is better to start from
here[^]

It will help you to create a standard login page in ASP.NET. :rose:


如果您使用的是Windows应用程序,请使用两个文本框和两个用于用户名和密码的标签来创建登录表单.将UseSystemPassword属性设置为true.然后,使用至少一个包含用户名和密码列的表创建sql数据库.这是一个示例代码:请注意,DataHelper是我的类,用于仅两行连接到SQL数据库,而LoginInfo是用于封装用户,其角色和权限的类.如果只需要用户名和密码,请忽略其余代码.

If you are using a windows application, create the login form with two textboxes and two labels for the username and password. Set the UseSystemPassword property to true. Then, create the sql database with at least a table with a username and a password column. Here is a sample code: Please note that DataHelper is my class for connecting to the SQL database in just two lines and LoginInfo is a class for encapsulating the user, his roles and rights. If you want just the user and password, ignore the rest of the code.

private LoginInfo Login()
        {
            LoginInfo result = new LoginInfo();
            try
            {
                DataHelperMS dh = new DataHelperMS();
                
                // Get the user
                String sql = String.Format(@"SELECT user_id, user_name
                            FROM  Users
                            WHERE (user_id = ''{0}'' AND user_password = ''{1}'')", txtUsername.Text.Replace("''", ""), txtPassword.Text.Replace("''", ""));
                DataTable userTable = dh.ExecuteDataSet(sql).Tables[0];
                result.User_id = userTable.Rows[0][0].ToString();
                result.User_name = userTable.Rows[0][1].ToString();
                
                // Get his roles
                String sql2 = String.Format(@"SELECT R.role_id, R.role_name
                            FROM  Roles R INNER JOIN UserRoles UR ON R.role_id = UR.ur_role_id 
                            WHERE (UR.ur_user_id = ''{0}'')", result.User_id);
                DataTable roleTable = dh.ExecuteDataSet(sql2).Tables[0];
                foreach (DataRow row in roleTable.Rows)
                {
                    result.Roles_ids.Add(row[0].ToString());
                    result.Roles_names.Add(row[1].ToString());
                }
                // Get his rights
                foreach (String id in result.Roles_ids)
                {
                    String sql3 = String.Format(@"SELECT R.right_id, R.right_name
                            FROM  Rights R INNER JOIN RoleRights RR ON R.right_id = RR.rr_right_id 
                            WHERE (RR.rr_role_id = ''{0}'')", id);
                    DataTable rightTable = dh.ExecuteDataSet(sql3).Tables[0];
                    foreach (DataRow row in rightTable.Rows)
                    {
                        result.Rights_ids.Add(row[0].ToString());
                        result.Rights_names.Add(row[1].ToString());
                    }
                }
            }
            catch (Exception) // User could not be found
            {
                result = null;
            }
            return result;
        }


我需要代码来解决此问题
除非您先尝试一下,否则没人会为您提供代码.

如何使用sqlser数据库检查用户名和密码
1.在登录表单的sumbit按钮上,获取用户名和密码
2.将组合传递到数据库进行验证
3.使用查询在数据库中验证组合是否有效.如果返回有效结果,则返回用户的真实/个人资料.
4.如果找到组合,则成功登录,否则失败.
I need code to solve this problem
No one will provide you code until you try yourself first.

How can i check username and password with sqlser database
1. On sumbit button of the login form, get the username and password
2. Pass on the combination to database for verification
3. Verify in the database if the combination is valid using a query. If you get back a valid result then return back true/profile of the user.
4. If combination was found, successful login or else failure.


这篇关于解决登录表单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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