Exemplo n.º 1
0
        //Validate User
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (textBoxUserName.IsFocused)
            {
                // Password text box will be disabled for biometric login
                if (textBoxPassword.IsEnabled != false)
                {
                    textBoxPassword.Focus();
                    return;
                }
                else
                {
                    // It means biometric login
                    buttonLogin.Focus();
                }
            }

            try
            {
                //#region Check plaza id mismatch in lane computer
                //try
                //{
                //    //Current computer plaza id which is mentioned in text file and plaza id in all tables must be same.
                //    if (!VaaaN.ATMS.Libraries.CommonLibrary.Constants.IsCurrentComputerLane() && !VaaaN.TollMax.Library.Constants.IsCurrentComputerHQMS())
                //    {
                //        bool plazaIdMismatch = false;

                //        //Get list of all tables
                //        ArrayList alTables = VaaaN.TollMax.Library.Constants.GetListOfAllDatabaseTables();

                //        //Check plaza id mismatch in all tables
                //        for (int i = 0; i < alTables.Count; i++)
                //        {
                //            string tableName = alTables[i].ToString();
                //            string query = "select count(*) from " + tableName + " where plaza_id <> " + plazaId;
                //            DbCommand cmd = VaaaN.TollMax.Library.DBF.DatabaseFunctions.GetSqlStringCommand(query);
                //            DataSet ds = VaaaN.TollMax.Library.DBF.DatabaseFunctions.LoadDataSet(cmd, tableName);

                //            if (tableName.ToLower() != "tbl_journey_plaza")
                //            {
                //                if (Convert.ToInt32(ds.Tables[0].Rows[0][0]) > 0)
                //                {
                //                    VaaaN.ATMS.Libraries.CommonLibrary.Logger.Log.Write("Plaza id is mismatched in table " + tableName, logModuleName);
                //                    plazaIdMismatch = true;
                //                }
                //            }
                //        }

                //        if (plazaIdMismatch)
                //        {
                //            labelErrorMessage.Content = "Plaza ID is mismatched, please contact to system administrator.";
                //            return;
                //        }
                //    }
                //}
                //catch (Exception ex)
                //{
                //    VaaaN.ATMS.Libraries.CommonLibrary.Logger.Log.Write("Failed to check plaza id mismatch." + ex.ToString(), logModuleName);
                //}
                //#endregion

                if (textBoxUserName.Text.Trim().Length == 0)
                {
                    labelErrorMessage.Content = hrm.GetString("Login_UserNameNotblank");
                    return;
                }

                if (textBoxPassword.Password.Trim().Length == 0 && checkBoxIsBiometricLogin.IsChecked != true)
                {
                    labelErrorMessage.Content = hrm.GetString("Login_PasswordNotblank");
                    return;
                }

                //Case insensensitive user name
                string loginName = this.textBoxUserName.Text.Trim().ToLower();
                //Case sensitive password
                string password = this.textBoxPassword.Password;

                Constants.LoginResult result = Constants.LoginResult.InvalidUser;

                try
                {
                    if (checkBoxIsBiometricLogin.IsChecked == true)
                    {
                        checkBoxIsBiometricLogin.IsChecked = false;
                        //If biometric login only
                        if (VerifyFingerPrint())
                        {
                            result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.Successful;
                        }
                        else
                        {
                            result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.FingerPrintNotMatched;
                            checkBoxIsBiometricLogin.IsChecked = true;
                            checkBoxIsBiometricLogin.IsEnabled = false;
                        }
                    }
                    else
                    {
                        //Check server connectivity

                        bool isPingSuccessful = true;

                        for (int i = 0; i < 5; i++)
                        {
                            //isPingSuccessful = VaaaN.MLFF.Libraries.CommonLibrary.Constants.IsPingSuccessful(generalConfig.AtmsServerIPAddress);

                            if (isPingSuccessful)
                            {
                                break;
                            }

                            System.Threading.Thread.Sleep(100);
                        }
                        isPingSuccessful = true;
                        if (isPingSuccessful)
                        {
                            result = VaaaN.MLFF.Libraries.CommonLibrary.BLL.LoginBLL.ValidateUser(loginName, password, ref currentUser);
                        }
                        else
                        {
                            result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.DatabaseServerNotConnected;
                        }
                    }

                    switch (result)
                    {
                    case Constants.LoginResult.Successful:
                        this.DialogResult = true;
                        break;

                    case Constants.LoginResult.InvalidUser:
                        this.labelErrorMessage.Content = hrm.GetString("Login_InvalidUser");
                        this.UnsuccessfulLogin();
                        break;

                    case Constants.LoginResult.DatabaseError:
                        this.labelErrorMessage.Content = hrm.GetString("CMN_LBL_DBError");
                        this.UnsuccessfulLogin();
                        break;

                    case Constants.LoginResult.InvalidPassword:
                        this.labelErrorMessage.Content = hrm.GetString("Login_InvalidPassword");
                        this.UnsuccessfulLogin(false);
                        break;

                    case Constants.LoginResult.CannotLogin:
                        this.labelErrorMessage.Content = hrm.GetString("Login_CanNotLogin");
                        this.UnsuccessfulLogin();
                        break;

                    case Constants.LoginResult.AccountExpired:
                        this.labelErrorMessage.Content = hrm.GetString("Login_UserAccountExpired");
                        this.UnsuccessfulLogin();
                        break;

                    case Constants.LoginResult.FingerPrintNotMatched:
                        this.labelErrorMessage.Content = "Finger Print Mismatched";
                        this.UnsuccessfulLogin();
                        break;

                    case Constants.LoginResult.DatabaseServerNotConnected:
                        this.labelErrorMessage.Content = "Database server not connected.";
                        this.UnsuccessfulLogin();
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    VaaaN.MLFF.Libraries.CommonLibrary.Logger.Log.Write("Failed to validate user." + ex.ToString(), logModuleName);
                    //VaaaN.TollMax.Library.CustomMessageBox.Show(ex.Message, trm.GetString("CMN_LBL_Error"), MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                    labelErrorMessage.Content = "Failed to validate user." + Environment.NewLine + ex.Message;
                    this.UnsuccessfulLogin();
                }

                if (loginAttempt == maxLoginAttempt)
                {
                    this.labelErrorMessage.Content = "Maximum login limit reached.";
                    this.loginAttempt = 0;
                }

                #region Delete 10 days older log files
                //try
                //{
                //    VaaaN.TollMax.Library.Constants.LogFileRemover();
                //}
                //catch (Exception ex)
                //{
                //    VaaaN.ATMS.Libraries.CommonLibrary.Logger.Log.Write("Failed to delete log file. " + ex.ToString(), VaaaN.TollMax.SharedLibrary.FileIO.Log.ErrorLogModule.Login);
                //}
                #endregion
            }
            catch (Exception ex)
            {
                VaaaN.MLFF.Libraries.CommonLibrary.Logger.Log.Write("Failed to initialize login form" + ex.ToString(), logModuleName);
            }
        }
Exemplo n.º 2
0
        public static BO_Users Login(HttpSessionStateBase session, string UserName, string Password, out Constants.LoginResult result)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                BO_Users user = new BO_Users();

                var obj = db.Users.Where(x => x.UserName == UserName && x.Password == Password && x.IsActive == true).FirstOrDefault();
                if (obj != null)
                {
                    result         = Constants.LoginResult.Success;
                    user.firstName = obj.FirstName;
                    user.lastName  = obj.LastName;
                    user.id        = obj.Id;
                    user.phone     = obj.Phone;
                    user.userId    = obj.UserName;
                    // user.adminRights = obj.AdminRights??false;
                }
                else
                {
                    result = Constants.LoginResult.WrongPwd;
                }

                return(user);
            }
        }