데이터베이스 테이블 "user"를 확인하여 동일한 사용자 이름을 다시 만들 수 없도록 "username"이 있는지 확인하려고합니다. 이 유효성 검사기를 사용자 이름이 존재하면 메시지 상자가 존재합니다 표시됩니다.사용자 이름이 이미 데이터베이스에 존재하는지 확인
이를 통해 저를 인도하십시오, 사용자 이름이 존재하는 경우 나는 추가하고 확인하기 위해 지금까지 버튼 뒤에 코드를 다음 있습니다 :
private void btnSignupNew_Click(object sender, EventArgs e)
{
if (txtUsername.Text == "")
{
errorUsername.SetError(txtUsername, "Enter A Username");
}
else if (txtPassword.Text == "")
{
errorPassword.SetError(txtPassword, "Enter A Valid Password");
}
//so if there isnt no error in the fields itll go on and add the data in to the database.
else{
//instance of sqlConnection
SqlConnection con = new SqlConnection("Data Source=etc");
//instance of sqlCommand
SqlCommand cmd = new SqlCommand("INSERT INTO [User] values ('" + txtForename.Text + "', '" + txtSurname.Text + "', '" + txtUsername.Text + "', '" + txtPassword.Text + "')", con);
con.Open();
cmd.ExecuteNonQuery();
//query executed correcty or not
con.Close();
당신은 SQL 주입 취약점을 가지고있다. – SLaks
** 암호를 일반 텍스트 **에 저장하지 마십시오. – SLaks
_SQL Injection_ 공격을 방지하려면 [매개 변수가있는 쿼리] (http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html)를 사용하십시오. –