Linux C#.net如何开发登录表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3677001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to develop login form C#.net
提问by Kumara
Please tell me how to build Windows form Login .(not ASP.net) . This login Should validate using not only windows Authentication method but also Database user.
请告诉我如何构建 Windows 表单登录。(不是 ASP.net)。此登录不仅应使用 Windows 身份验证方法进行验证,还应使用数据库用户进行验证。
How validate User name and password. I used this type of Query for it
如何验证用户名和密码。我使用了这种类型的查询
SELECT COUNT(*) FROM [Table Name] WHERE UserName = @username AND Password = @password;
If user available count >0Above part handle code side.
如果用户可用计数 >0以上部分处理代码侧。
using int x = Int32.Parse(commandObject.ExecuteScalar().ToString());
if(x > 0}
**log**
else
**fail**
How Can I do it professional and correct way?
我怎样才能做到专业和正确的方式?
回答by Hans Olsson
Since you have the SQL already, all you need is a basic form, there's nothing special about a login form except that you hide the password, you can do that using the TextBox.PasswordCharproperty.
因为您已经有了 SQL,所以您只需要一个基本表单,登录表单没有什么特别之处,只是您隐藏了密码,您可以使用TextBox.PasswordChar属性来做到这一点。
回答by Sebastian Edelmeier
What do you mean by "Windows Authentication"? You could read the logged in User from the Environment and prefill the user-textfield with this value.
“Windows 身份验证”是什么意思?您可以从环境中读取登录的用户并使用此值预填充用户文本字段。
tbUserName = Environment.UserName;
After the User has entered his password, your setup dictates what to do. Is the Password Database Hashed (MD5, SHA1) or Verbatim? If so, hash the entered Password - or don't if it isn't.
用户输入他的密码后,您的设置将指示要执行的操作。密码数据库是散列的(MD5、SHA1)还是逐字的?如果是这样,请散列输入的密码 - 如果不是,则不要。
You could use those two strings to select entities from your DataSource using the technology of your preference (e.g. ADO.Net). If no results are returned, the login was faulty. Remember: That way you won't be able to tell whether just the password or the user or both were wrong.
您可以使用这两个字符串使用您偏好的技术(例如 ADO.Net)从您的数据源中选择实体。如果没有返回结果,则登录失败。请记住:这样您将无法判断是密码错误还是用户错误,或者两者都错误。
回答by balexandre
"Professional and correct way"
“专业正确的方式”
This can depend on what you application does, do you allow any kinda content to be seen or the first think should be login?
这可能取决于您的应用程序做什么,您是否允许看到任何内容,或者首先认为应该登录?
If yes:
如果是:
- Create a Window Form with your login screen
- upon "login" button is clicked, check the sql the way you want
- if ok, close that window and do a
form.Show()
the main window of your application - else, just give a good reason that you don't allow the user to proceed
- 使用您的登录屏幕创建一个窗口窗体
- 单击“登录”按钮后,按照您想要的方式检查 sql
- 如果可以,请关闭该窗口并执行
form.Show()
应用程序的主窗口 - 否则,只需给出一个不允许用户继续的充分理由
if windows authentication, you need to check if that windows user can access it, do the same procedure but you do act upon formLogin.Active
for example, and ask for credentials if that Windows User is not a valid user and do the above process again.
如果 Windows 身份验证,您需要检查该 Windows 用户是否可以访问它,执行相同的过程,但您确实会采取行动formLogin.Active
,如果该 Windows 用户不是有效用户,则要求提供凭据,然后再次执行上述过程。
As an example, SuperOffice CRM 6Application for windows, have this login form:
例如,适用于 Windows 的SuperOffice CRM 6应用程序,具有以下登录表单:
alt text http://www.balexandre.com/temp/2010-09-09_1557.png
替代文字 http://www.balexandre.com/temp/2010-09-09_1557.png
I hope it helps to get an idea.
我希望它有助于获得一个想法。
If you were asking about code only, then you already have good answers.
如果您只询问代码,那么您已经有了很好的答案。
回答by Jeremy
Just a thought... Have your login as the first screen your user visits. If they pass, then show the main app form and hide the login. If they fail, simply display a message stating that. It's not like web apps where a user can type in a url and try to get to any page they want to. You have FULL CONTROL :)
只是一个想法......让您的登录作为您的用户访问的第一个屏幕。如果他们通过,则显示主应用程序表单并隐藏登录。如果失败,只需显示一条消息说明。它不像网络应用程序,用户可以在其中输入 url 并尝试访问他们想要的任何页面。你有完全的控制权:)