Example #1
0
        private void Login_Click(object sender, EventArgs e)
        {
            CancelEventArgs cea = new CancelEventArgs();

            userName_Validating(sender, cea);
            password_Validating(sender, cea);

            if (cea.Cancel == false)
            {
                UserService.UserServiceClient usermanage = new UserService.UserServiceClient();
                try
                {
                    MD5CryptoServiceProvider Md5 = new MD5CryptoServiceProvider();
                    byte[] passwordBytes         = Encoding.UTF8.GetBytes(this.txtPassword.Text);
                    byte[] hashCode        = Md5.ComputeHash(passwordBytes);
                    string encryptPassword = BitConverter.ToString(hashCode).Replace(LINE, Constants.emptyStr);
                    bool   result          = usermanage.VerifyUserLogin(this.txtUsername.Text, encryptPassword);

                    if (result == true)
                    {
                        RememberSomeParameter.username = this.txtUsername.Text;
                        RememberSomeParameter.userId   = Convert.ToInt32(usermanage.queryUserIdByName(this.txtUsername.Text));
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.lblPassErrorMessage.Visible = true;
                        this.lblErrorMessage.Text        = NOT_CORRECT_PASS;
                        this.lblErrorMessage.Visible     = true;
                    }
                }
                catch (FaultException <UserNameNotExistent> )
                {
                    this.lblUsernameErrorMessage.Visible = true;
                    this.lblErrorMessage.Text            = USER_NAME_NOT_EXIST;
                    this.lblErrorMessage.Visible         = true;
                }
                catch (CommunicationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (Exception exx)
                {
                    Console.WriteLine(exx.Message);
                }
            }
        }
Example #2
0
        private void Login_Click(object sender, EventArgs e)
        {
            CancelEventArgs cea = new CancelEventArgs();

            UserName_Validating(sender, cea);
            Password_Validating(sender, cea);

            if (cea.Cancel == false)
            {
                UserService.UserServiceClient userManager = new UserService.UserServiceClient();
                try
                {
                    string encryptPassword = EncryptUtils.EncryptPassword(this.txtPassword.Text);
                    bool   result          = userManager.VerifyUserLogin(this.txtUsername.Text.Trim(), encryptPassword);

                    if (result == true)
                    {
                        RememberUserParameter.username = this.txtUsername.Text.Trim();
                        RememberUserParameter.userId   = Convert.ToInt32(userManager.QueryUserIdByName(this.txtUsername.Text.Trim()));

                        //remember password
                        if (this.lblSelect.Visible)
                        {
                            UserInfo user = new UserInfo();
                            user.UserName = this.txtUsername.Text.Trim();
                            user.Password = this.txtPassword.Text.Trim();
                            FileStream      fs = new FileStream(passwordFilePath, FileMode.Create);
                            BinaryFormatter bf = new BinaryFormatter();
                            bf.Serialize(fs, user);
                            fs.Close();
                        }
                        else
                        {
                            FileStream fs = new FileStream(passwordFilePath, FileMode.Open, FileAccess.Write);
                            if (fs.Length > 0)
                            {
                                fs.SetLength(0);
                                fs.Close();
                            }
                        }

                        Log4NetHelper.WriteInfoLog(typeof(LoginForm), "Login successfully!");
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.lblPassErrorMessage.Visible = true;
                        this.lblErrorMessage.Text        = ResourceCulture.GetString(NOT_CORRECT_PASS);
                        this.lblErrorMessage.Visible     = true;
                        Log4NetHelper.WriteInfoLog(typeof(LoginForm), "Password error!");
                    }
                }
                catch (FaultException <UserNameNotExistent> )
                {
                    this.lblUsernameErrorMessage.Visible = true;
                    this.lblErrorMessage.Text            = ResourceCulture.GetString(USER_NAME_NOT_EXIST);
                    this.lblErrorMessage.Visible         = true;
                    Log4NetHelper.WriteInfoLog(typeof(LoginForm), "User isn't existent!");
                }
                catch (CommunicationException ex)
                {
                    Log4NetHelper.WriteErrorLog(typeof(LoginForm), ex);
                }
                catch (Exception exx)
                {
                    Log4NetHelper.WriteErrorLog(typeof(LoginForm), exx);
                }
            }
        }