Ejemplo n.º 1
0
        // ユーザーログイン時、パスワードとログイン状態の確認(2重ログインの防止)
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            if (btnLogIn.Text == "Log In")
            {
                TfSQL  tf   = new TfSQL();
                string logt = tf.sqlExecuteScalarString("select login_times from qc_user where qcuser = '******'");
                if (logt == "0")
                {
                    grLogin.Text         = "Change Default Password";
                    lblUser.Text         = "New Password";
                    txtPwd.Size          = new Size(100, 20);
                    txtPwd.Location      = new Point(123, 47);
                    lblPass.Text         = "Confirm Password";
                    txtPassword.Size     = new Size(100, 20);
                    txtPassword.Location = new Point(123, 87);
                    btnLogIn.Text        = "Change Password";
                    btnLogIn.Enabled     = false;
                    txtPassword.ResetText();
                    txtPwd.ResetText();
                    txtPwd.Visible = true;
                    txtPwd.Focus();
                    cmbUserName.Visible   = false;
                    btnChangePass.Visible = false;
                }
                else
                {
                    string sql   = null;
                    string user  = null;
                    string pass  = null;
                    string ip    = null;
                    bool   login = false;

                    user = cmbUserName.Text;

                    if (user != null)
                    {
                        sql  = "select pass FROM qc_user WHERE qcuser='******'";
                        pass = tf.sqlExecuteScalarString(sql);

                        sql   = "select loginstatus FROM qc_user WHERE qcuser='******'";
                        login = tf.sqlExecuteScalarBool(sql);

                        sql = "select ip_address from qc_user where qcuser = '******'";
                        ip  = tf.sqlExecuteScalarString(sql);


                        GetMD5(txtPassword.Text);

                        if (pass == str_md5)
                        {
                            if (login && ip != "null" && ip != lblIP.Text)
                            {
                                DialogResult reply = MessageBox.Show("This user account is currently used by " + ip + "," + System.Environment.NewLine +
                                                                     "or the log out last time had a problem.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                                sql = "UPDATE qc_user SET loginstatus=false, ip_address = '" + lblIP.Text + "' WHERE qcuser='******'";
                                bool res1 = tf.sqlExecuteNonQuery(sql, false);
                                return;
                            }

                            //Check IP Address
                            if (ip == "null")
                            {
                                tf.sqlExecuteScalarString("UPDATE qc_user SET ip_address = '" + lblIP.Text + "' where qcuser = '******'");
                            }

                            // ログイン状態をTRUEへ変更
                            sql = "UPDATE qc_user SET loginstatus=true WHERE qcuser='******'";
                            bool res = tf.sqlExecuteNonQuery(sql, false);

                            // 子フォームForm1を表示し、デレゲートイベントを追加:
                            frmItem f1 = new frmItem();
                            f1.RefreshEvent += delegate(object sndr, EventArgs excp)
                            {
                                // Form1を閉じる際、ログイン状態をFALSEへ変更し、当フォームForm5も閉じる
                                sql          = "UPDATE qc_user SET loginstatus=false, ip_address = 'null' WHERE qcuser='******'";
                                res          = tf.sqlExecuteNonQuery(sql, false);
                                this.Visible = true;
                                txtPassword.ResetText();
                            };
                            f1.updateControls(user, lblIP.Text);
                            f1.Show();
                            this.Visible = false;
                        }
                        else if (pass != txtPassword.Text)
                        {
                            MessageBox.Show("Password does not match", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            txtPassword.ResetText();
                        }
                    }
                }
            }
            else
            {
                if (txtPwd.Text != txtPassword.Text)
                {
                    lblStatus.Text      = "Password is not avaliable!";
                    lblStatus.ForeColor = Color.Red;
                }
                else
                {
                    string pass = txtPwd.Text;
                    GetMD5(pass);
                    TfSQL up = new TfSQL();
                    up.sqlExecuteScalarString("update qc_user set pass = '******' where qcuser = '******'");
                    up.sqlExecuteScalarString("update qc_user set login_times = '1' where qcuser = '******'");
                    btnLogIn.Text        = "Log In";
                    lblUser.Text         = "Username:"******"Password:"******"Your password has been changed!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (result == DialogResult.OK)
                    {
                        login();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void login()
        {
            string sql   = null;
            string user  = null;
            string pass  = null;
            string ip    = null;
            bool   login = false;

            user = cmbUserName.Text;

            if (user != null)
            {
                TfSQL tf = new TfSQL();
                sql  = "select pass FROM qc_user WHERE qcuser='******'";
                pass = tf.sqlExecuteScalarString(sql);

                sql   = "select loginstatus FROM qc_user WHERE qcuser='******'";
                login = tf.sqlExecuteScalarBool(sql);

                sql = "select ip_address from qc_user where qcuser = '******'";
                ip  = tf.sqlExecuteScalarString(sql);

                //Check IP Address
                if (ip == "null")
                {
                    tf.sqlExecuteScalarString("UPDATE qc_user SET ip_address = '" + lblIP.Text + "'");
                }

                GetMD5(txtPassword.Text);

                if (pass == str_md5)
                {
                    if (login && ip != "null" && ip != lblIP.Text)
                    {
                        DialogResult reply = MessageBox.Show("This user account is currently used by " + ip + "," + System.Environment.NewLine +
                                                             "or the log out last time had a problem.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                        return;
                    }

                    // ログイン状態をTRUEへ変更
                    sql = "UPDATE qc_user SET loginstatus=true WHERE qcuser='******'";
                    bool res = tf.sqlExecuteNonQuery(sql, false);

                    // 子フォームForm1を表示し、デレゲートイベントを追加:
                    frmItem f1 = new frmItem();
                    f1.RefreshEvent += delegate(object sndr, EventArgs excp)
                    {
                        // Form1を閉じる際、ログイン状態をFALSEへ変更し、当フォームForm5も閉じる
                        sql          = "UPDATE qc_user SET loginstatus=false, ip_address = 'null' WHERE qcuser='******'";
                        res          = tf.sqlExecuteNonQuery(sql, false);
                        this.Visible = true;
                        txtPassword.ResetText();
                    };
                    f1.updateControls(user, lblIP.Text);
                    f1.Show();
                    this.Visible = false;
                }
                else if (pass != txtPassword.Text)
                {
                    MessageBox.Show("Password does not match", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtPassword.ResetText();
                }
            }
        }