사용자 이름과 암호 열이있는 SQL 데이터베이스가 있습니다. 사용자에게 유효한 사용자 이름과 암호를 입력하도록 요청하는 로그인 양식을 만들었습니다.
잘못된 항목에 대한 검사는 이미 작동하지만 사용자 이름 암호 조합이 정상일 때 검사는 실패합니다.
namespace Kartice
{
public partial class Pass : Form
{
Matjaz Matjaz = new Matjaz();
public Pass()
{
// string myconnection = @"C:\Users\Bojan\Desktop\Programiranje\School\Kartice\Kartice\Users.mdf";
InitializeComponent();
}
private void usersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.usersBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.usersDataSet);
}
private void Pass_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'usersDataSet.Users' table. You can move, or remove it, as needed.
this.usersTableAdapter.Fill(this.usersDataSet.Users);
}
private void BtnOk_Click(object sender, EventArgs e)
{
if (Imetxt.Text == "")
{
MessageBox.Show("Please enter a valid user name!");
Imetxt.Focus();
}
else if (Passtxt.Text == "")
{
MessageBox.Show("Please enter a valid password!");
Passtxt.Focus();
}
string userName1, userPassword1;
userName1 = Imetxt.Text;
userPassword1 = Passtxt.Text;
foreach (DataRow row in usersDataSet.Users)
{
if (row["Ime_Priimek"].ToString() == userName1)
{
if (row["Password"].ToString() == userPassword1)
{
Pass myForm1 = new Pass();
Matjaz myForm2 = new Matjaz();
myForm2.Show();
myForm1.Hide();
break;
}
}
else
MessageBox.Show("You have entered a wrong user name or the password!");
}
}
MessageBox
인 내부for
루프.테이블에 5 명의 사용자가 있다고 가정합니다.
luke
사용자 이름과 올바른 암호를 입력했다고 가정 해 보겠습니다 .
=======================
| Username | Password |
|- - - - - | - - - - -|
| matthew | ***** |
| mark | ***** |
| luke | ***** |
| john | ***** |
=======================
사용자 이름 luke
은이 표에서 세 번째입니다.
프로그램이 수행하는 작업은 다음과 같습니다.
<<start>>
Is 'matthew' equal to 'luke'?
- No! Display a message box.
Is 'mark' equal to 'luke'?
- No! Display a message box.
Is 'luke' equal to 'luke'?
- Yes!
- Is '****' equal to '****'?
- Yes! Show Form2 and hide Form1.
<<end>>
이제 문제가 명확 해 졌으면합니다. 가장 먼저해야 할 일은 루프 MessageBox
밖으로 이동하는 것입니다 for
.
bool userFound = false;
foreach (DataRow row in usersDataSet.Users)
{
if (row["Ime_Priimek"].ToString() == userName1)
{
if (row["Password"].ToString() == userPassword1)
{
userFound = true;
Pass myForm1 = new Pass();
Matjaz myForm2 = new Matjaz();
myForm2.Show();
myForm1.Hide();
break;
}
}
}
if (!userFound)
{
MessageBox.Show("You have entered a wrong user name or the password!");
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다