且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置类型的输入变量的值="密码"使用C#和ASP.Net

更新时间:2023-02-15 19:48:37

不要设置输入类型在您的标记或呈现前ASP.NET将清除输入。相反,使用以下标记:

Don't set the input type in your markup or ASP.NET will clear the input before it is rendered. Instead, use the following markup:

<input id="tbPassword" name="password" runat="server" />

...及以下code在code-背后:

...and the following code in your code-behind:

tbPassword.Value = "your password";
tbPassword.Attributes["type"] = "password";

不过,我强烈反对这种做法。其一,你不应该采用明文存储密码。这是一个非常糟糕的安全做法。

However, I strongly advise against this approach. For one, you shouldn't be storing passwords in plain text. It's a really bad security practice.

二,如果你只是要设置code中的密码,为什么需要它呢?一个密码输入的点是为用户交互(输入密码)。如果你这样做对他们来说,然后有在页面上是没有意义的。

Two, if you're just going to set the password in code, why require it at all? The point of a password input is for user interaction (entering a password). If you do that for them, then having it on the page is pointless.