일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 원한
- Python
- 가상환경
- DataTables
- geckodriver
- 분노
- 맥코트
- JQuery
- Linux
- STS
- 말라키
- Eclipse
- 리눅스
- checkbox
- error
- build
- HMI
- pythoncom37.dll
- Anaconda
- 명령어
- SCADA
- 파이썬
- Custom
- LOG
- ORA-28002
Archives
- Today
- Total
2010년 5월 1일, 2막
[C#] 로그인 처리 하기 본문
출처 : http://hazelstyle.egloos.com/4978143
private void button1_Click(object sender, EventArgs e) { if (textID.Text.Trim() == "" || textPwd.Text.Trim() == "") { if (MessageBox.Show("아이디와 암호를 입력해 주세요.", "아이디 입력 오류", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.Retry) { textID.Text = ""; textPwd.Text = ""; } } else { int res = Authenticate(textID.Text.Trim(), textPwd.Text.Trim()); if (res > 0) { this.DialogResult = DialogResult.OK; } else { switch (res) { case -1: if (MessageBox.Show("아이디를 잘못 입력하였습니다.", "사용자 로그인 오류", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { textID.Text = ""; textPwd.Text = ""; } else this.DialogResult = DialogResult.Cancel; break; case -2: if (MessageBox.Show("암호를 잘못 입력하였습니다.", "사용자 로그인 오류", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { textPwd.Text = ""; } else this.DialogResult = DialogResult.Cancel; break; default: MessageBox.Show("ISM-DVS 시스템 오류입니다. 관리자에게 문의하세요.", "사용자 로그인 오류", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.DialogResult = DialogResult.Cancel; break; } } } } private int Authenticate (string id, string pwd) { string con_str = "server=127.0.0.1; database=xxx; user id = sa; password=1111;"; SqlConnection con = new SqlConnection(con_str); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "select pwdcompare(@pwd,passwd), idx from users where userid = @id"; cmd.Parameters.Add("@id", SqlDbType.VarChar, 20); cmd.Parameters.Add("@pwd", SqlDbType.VarChar, 50); cmd.Parameters["@id"].Value = id; cmd.Parameters["@pwd"].Value = pwd; SqlDataReader reader = null; try { con.Open(); reader = cmd.ExecuteReader(); if (reader.Read()) { if ((int)reader[0] > 0) return 1; else return -2; // 암호 오류 } else return -1; // 아이디 오류 } catch { MessageBox.Show("데이터 베이스 접속 오류", "사용자 확인"); return -99; } finally { if (reader != null) reader.Close(); con.Close(); } }
'Computer' 카테고리의 다른 글
RAID (0) | 2013.04.16 |
---|---|
[C#] mdb handling (0) | 2013.04.13 |
[C#] 파일명과 확장자 추출 예제 (0) | 2013.04.03 |
[C#] OpenFileDialog에서 경로 가지고 오기 (0) | 2013.04.03 |
[C#] 상속받은 Form의 버튼을 수정하고자 할 때 (0) | 2013.04.02 |