简体   繁体   English

登录表单身份验证 C#

[英]Login Form Authentication C#

I create a stored procedure name sp_Auth and inside it is Table name UserAccounts with two fields, username and password both varchar(50) I declared two variables, @username,@password on stored procedure我创建了一个名为sp_Auth的存储过程,其中包含两个字段的表名UserAccountsusernamepassword都是varchar(50)我在存储过程中声明了两个变量, @username,@password

Select * From UserAccounts where @username = username and @password = password

After I create it I put it into Linq to SQL together with the table and then I create new class to call the stored procedure from the linq to sql class.创建它后,我将它与表一起放入 Linq to SQL 中,然后创建新类以从 linq to sql 类调用存储过程。

My question is how do I make a method in order for the button in my login form to check or validate username and password typed in the textboxes to the data found on the table using my stored procedure.我的问题是如何制作一种方法,以便我的登录表单中的按钮使用我的存储过程检查或验证在文本框中键入的用户名和密码到表上的数据。

I know there are a lot of ways on doing this but I found out they uses sqlcommand or something.我知道有很多方法可以做到这一点,但我发现他们使用 sqlcommand 或其他东西。

I need to use the class to call the stored proc.我需要使用该类来调用存储过程。

The code I want to achieve is like this我要实现的代码是这样的

Public static sp_Insert(Product p) db = new dataclass1context(); public static sp_Insert(Product p) db = new dataclass1context(); db.storedprocInsert(@Name,@Pname); db.storedprocInsert(@Name,@Pname); Can I create a validator or checker in the class like the code above?我可以像上面的代码一样在类中创建验证器或检查器吗?

Take a look at Passing parameter to stored procedure .看看将参数传递给存储过程 This will get you on the way.这会让你顺利上路。 You can use the result of the query to determine if the user was validated.您可以使用查询结果来确定用户是否经过验证。

Please keep in mind that passwords should not be stored as plaintext, and should be at least hashed and even salted, which would require you to convert the users password to the matching type of hash before your query.请记住,密码不应以明文形式存储,至少应进行散列甚至加盐,这将要求您在查询之前将用户密码转换为匹配的散列类型。

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

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