我之前创建了一个有效的字符串密码,但不能用于其他形式的身份验证。所以我创建了一个包含密码的本地服务器数据库表。然后我将此表和密码调用到GetPass表单中,该表单用于验证对其他表单的访问权限。然而,由于知识有限,我努力实现这一目标,任何提示或示例都将受到高度赞赏。 (在字符串密码尝试的代码方法中仍然可见)
namespace BooyaaBrowser
{
public partial class GetPass : Form
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=BooyaaBrowser;Integrated Security=True");
private TextBox PasstextBox;
private Button btn_confirm;
private Label EnterPass;
private string refPassword;
public GetPass(string Password)
{
InitializeComponent();
refPassword = Password;
}
private void btn_confirm_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from password where password =('" + PasstextBox.Text + "')";
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception)
{
}
// string password = PasstextBox.Text;
//if (password.CompareTo(refPassword) == 0)
// {
// this.DialogResult = DialogResult.OK;
}
// this.Close();