私が行っていることがログイン環境の良い習慣とみなされているかどうかを尋ねたいと思っていました。私が作成しているソフトウェアを使用するためにログインサーバーに対して認証するSaaSを作成していますが、私が持っているアプローチが正しいものであれば、あなたの考えを見るために私がここで行ったことを投稿します!あなたのコメントのためにすべてを事前にありがとう。これは良いログインですか、データベースの習慣に対してユーザーを確認していますか?
private void AcceptButton_Click(object sender, EventArgs e)
{
bool loginSuccesful = false;
if (string.IsNullOrEmpty(usernameTextBox.Text))
{
MessageBox.Show("Por favor introduzca su Usuario.");
usernameTextBox.Focus();
}
else
{
try
{
string connectionString = ConfigurationSettings.AppSettings["IntegraTDB"].ToString().Trim();
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from dbo.Users where Username = @Username and Password = @Password", con);
cmd.Parameters.AddWithValue("@Username", usernameTextBox.Text);
cmd.Parameters.AddWithValue("@Password", passwordTextBox.Text);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
loginSuccesful = true;
}
dr.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error de autenticación: " + ex.Message);
}
if (loginSuccesful == true)
{
role_Extraction();
IIdentity identity;
identity = new GenericIdentity(usernameTextBox.Text);
IPrincipal principal = new GenericPrincipal(identity, _roles);
Thread.CurrentPrincipal = principal;
MessageBox.Show("Bienvenido a IntegraT!");
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("Usuario y/o Contraseña incorrectos.");
}
}
}
ユーザーパスワードはプレーンテキストで保存しています。だから*いいえ*、これは***ではありません。潜在的に有用な例外情報を 'catch'ブロックに投げ捨てています。 – David
あなたが必要とする列だけを選択するためにクエリを変更して、あなたがチェックしている/戻っている場合、初心者のために 'select *からdbo.Users'を選択してください..' PrincipalContextをいくつかの基本的なADコードと共に使う 'この行の使用 'this.DialogResult = DialogResult.OK;' – MethodMan
非常に多くの(正しく書かれた)セキュリティモジュールが利用可能です。 – user2864740