Esempio n. 1
0
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;

            Owner owner = service.getOwner();

            if (User.Username == owner.Username && password == owner.Password)
            {
                AddUser add = new AddUser();
                view.Close();
                add.Show();
            }
            else if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (User.Username == UserList[i].Username && password == UserList[i].Password)
                    {
                        LoggedInUser.CurrentUser = new tblUser()
                        {
                            UserID      = UserList[i].UserID,
                            Name        = UserList[i].Name,
                            DateOfBirth = UserList[i].DateOfBirth,
                            Email       = UserList[i].Email,
                            Username    = UserList[i].Username,
                            Password    = UserList[i].Password
                        };

                        LabelInfo = "Logged in";
                        found     = true;

                        int id = service.getUserId(User.Username);


                        if (service.IsManager(id))
                        {
                            Manager man = new Manager();
                            view.Close();
                            man.Show();
                        }
                        else if (service.IsEmployee(id))
                        {
                            Employee emp = new Employee();
                            view.Close();
                            emp.Show();
                        }
                        break;
                    }
                }

                if (found == false)
                {
                    LabelInfo = "Wrong Username or Password";
                }
            }

            #endregion
        }
Esempio n. 2
0
 public User GetUser(string username)
 {
     if ((UserList.Any(u => u.Name.Equals(username, StringComparison.InvariantCultureIgnoreCase))))
     {
         return(UserList.WithName(username).Clone());
     }
     return(null);
 }
Esempio n. 3
0
 public User GetUser(int userId)
 {
     if (UserList.Any(u => u.Id == userId))
     {
         return(UserList.WithId(userId).Clone());
     }
     return(null);
 }
Esempio n. 4
0
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;

            if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (User.Username == UserList[i].Username && password == UserList[i].UserPassword)
                    {
                        LoggedUser.CurrentUser = new tblUser
                        {
                            UserID       = UserList[i].UserID,
                            FirstName    = UserList[i].FirstName,
                            LastName     = UserList[i].LastName,
                            JMBG         = UserList[i].JMBG,
                            DateOfBirth  = UserList[i].DateOfBirth,
                            BankAccount  = UserList[i].BankAccount,
                            Email        = UserList[i].Email,
                            Position     = UserList[i].Position,
                            Salary       = UserList[i].Salary,
                            Username     = UserList[i].Username,
                            UserPassword = UserList[i].UserPassword,
                            Sector       = UserList[i].Sector,
                            Access       = UserList[i].Access
                        };

                        MainWindow mw = new MainWindow();
                        InfoLabel = "Loggedin";
                        found     = true;
                        view.Close();
                        mw.Show();
                        break;
                    }
                }

                if (found == false)
                {
                    InfoLabel = "Wrong Username or Password";
                }
            }
            else
            {
                InfoLabel = "Database is empty";
            }

            if (User.Username == "WPFadmin" && password == "WPFadmin")
            {
                Admin admin = new Admin();
                view.Close();
                admin.Show();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;

            if (User.Username == Admin.AdminUsername && password == Admin.AdminPassword)
            {
                InfoLabel = "Logged in";

                AllUsers addUser = new AllUsers();
                view.Close();
                addUser.Show();
            }
            else if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (User.Username == UserList[i].Username && password == UserList[i].UserPassword)
                    {
                        LoggedUser.CurrentUser = new tblUser
                        {
                            UserID       = UserList[i].UserID,
                            FirstName    = UserList[i].FirstName,
                            LastName     = UserList[i].LastName,
                            DateOfBirth  = UserList[i].DateOfBirth,
                            Email        = UserList[i].Email,
                            Username     = UserList[i].Username,
                            UserPassword = UserList[i].UserPassword
                        };
                        InfoLabel = "Logged in";
                        found     = true;
                        if (service.GetAllManagers().Any(id => id.UserID == UserList[i].UserID) == true)
                        {
                            AllUsers users = new AllUsers();
                            view.Close();
                            users.Show();
                        }
                        else if (service.GetAllEmployees().Any(id => id.UserID == UserList[i].UserID) == true)
                        {
                            Employee emp = new Employee();
                            view.Close();
                            emp.Show();
                        }
                        break;
                    }
                }

                if (found == false)
                {
                    InfoLabel = "Wrong Username or Password";
                }
            }
        }
Esempio n. 6
0
        public async override Task Init()
        {
            await base.CheckAppCenter();

            await base.CheckBadQueuedRecords();

            UserList = (await DataRetrievalService.GetAllUsers()).ToObservableCollection();
            if (UserList.Any())
            {
                SelectedUser = UserList[0];
            }
        }
        private void LoginConfirm(object arg)
        {
            var passwordBox = (PasswordBox)arg;

            if (UserList.Any(x => x.Login == LoginName) && UserList.Any(x => x.Password == passwordBox.Password))
            {
                //dialogService.ShowMessageBox(LocalizationProvider.GetLocalizedValue<String>("LoginSuccessful"));
                OnViewChanged("ContactBook");
            }
            else
            {
                dialogService.ShowMessageBox(LocalizationProvider.GetLocalizedValue <String>("InvalidLogin"));
            }
        }
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;

            if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (User.JMBG == UserList[i].JMBG && password == "Gost")
                    {
                        Service.loggedUser.Add(UserList[i]);
                        Service.currentUser = UserList[i];

                        if (service.CheckOrderStatus(UserList[i].UserID))
                        {
                            MessageBox.Show("Your order is pending.");
                            Login log = new Login();
                            log.Show();
                            view.Close();
                        }
                        else
                        {
                            MainWindow mw = new MainWindow();
                            LabelInfo = "Logged in";
                            found     = true;
                            view.Close();
                            mw.Show();
                            break;
                        }
                    }
                }

                if (found == false)
                {
                    LabelInfo = "Wrong Username or Password";
                }
            }
            else
            {
                LabelInfo = "Database is empty";
            }

            if (User.JMBG == "Zaposleni" && password == "Zaposleni")
            {
                Employee employee = new Employee();
                view.Close();
                employee.Show();
            }
        }
Esempio n. 9
0
        private void SignupConfirm(object arg)
        {
            var passwordBox = (PasswordBox)arg;
            var Password    = passwordBox.Password;

            if (UserList.Any(x => x.Login == LoginName))
            {
                dialogService.ShowMessageBox(LocalizationProvider.GetLocalizedValue <String>("LoginExists"));
            }
            else
            {
                UserList.Add(new User {
                    Login = LoginName, Password = Password, FirstName = FirstName, LastName = LastName
                });
                dataService.SaveUsers(UserList);
                dialogService.ShowMessageBox(LocalizationProvider.GetLocalizedValue <String>("SignupSuccessful"));
                OnViewChanged("Login");
            }
        }
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;

            if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (username == UserList[i].Username && PasswordHasher.Verify(password, UserList[i].UserPassword) == true)
                    {
                        LoggedInUser.CurrentUser = new tblUser
                        {
                            UserID       = UserList[i].UserID,
                            FirstName    = UserList[i].FirstName,
                            LastName     = UserList[i].LastName,
                            Email        = UserList[i].Email,
                            DateOfBirth  = UserList[i].DateOfBirth,
                            UserLocation = UserList[i].UserLocation,
                            Gender       = UserList[i].Gender,
                            Username     = UserList[i].Username,
                            UserPassword = UserList[i].UserPassword
                        };
                        found = true;

                        UserWindow userWindow = new UserWindow();
                        view.Close();
                        userWindow.Show();

                        break;
                    }
                }
            }

            if (found == false)
            {
                InfoText  = "Wrong Username or Password";
                InfoColor = "#FFF34A4A";
                SnackInfo();
            }
        }
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;

            if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (User.Username == UserList[i].Username && password == UserList[i].UserPassword)
                    {
                        Service.LoggedInUser.Add(UserList[i]);
                        MainWindow mw = new MainWindow();
                        InfoLabel = "Loggedin";
                        found     = true;
                        view.Close();
                        mw.Show();
                        break;
                    }
                }

                if (found == false)
                {
                    InfoLabel = "Wrong Username or Password";
                }
            }
            else
            {
                InfoLabel = "Database is empty";
            }

            if (User.Username == "WPFadmin" && password == "WPFadmin")
            {
                Admin admin = new Admin();
                view.Close();
                admin.Show();
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;

            if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (User.JMBG == UserList[i].JMBG && password == "Gost")
                    {
                        Service.LoggedInUser.Add(UserList[i]);
                        MainWindow mw = new MainWindow();
                        InfoLabel = "Logged in";
                        found     = true;
                        view.Close();
                        mw.Show();
                        break;
                    }
                }

                if (found == false)
                {
                    InfoLabel = "Wrong Username or Password";
                }
            }
            else
            {
                InfoLabel = "Database is empty";
            }

            if (User.JMBG == "Zaposleni" && password == "Zaposleni")
            {
                Worker worker = new Worker();
                view.Close();
                worker.Show();
            }
        }
 public static bool UserExist(int UserID)
 {
     return(UserList.Any(d => d.Id == UserID));
 }
 public static bool CookieIdExist(int UserID)
 {
     return(UserList.Count(d => d.Id == UserID) == 0 || UserList.Any(d => d.Id == UserID && d.SessionId == CookieSessionId));
 }
Esempio n. 15
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            string lockoutMsg = "";
            User   u          = null;
            bool   validUser  = users.Any(x => ((User)x).userLogin.ToLower() == usernameTextBox.Text.ToLower());

            if (validUser)
            {
                u = (User)(users.First(x => ((User)x).userLogin.ToLower() == usernameTextBox.Text.ToLower()));
            }

            // begin jdg 10/30/15
            NameValueCollection values = Configurator.GetConfig("AppSettings");

            if (values != null)
            {
                LDAPSecurityContext = values["SecurityContext"];
            }
            if (String.IsNullOrEmpty(LDAPSecurityContext))
            {
                LDAPSecurityContext = "Off";
            }
            bool bLDAPSuccess = false;
            bool bLDAP        = (((LDAPSecurityContext.ToUpper() == "MACHINE") || (LDAPSecurityContext.ToUpper() == "DOMAIN")) ? true : false);

            try
            {
                if (bLDAP)
                {
                    switch (LDAPSecurityContext.ToUpper())
                    {
                    case "MACHINE":
                        using (var context = new PrincipalContext(ContextType.Machine))
                        {
                            if (context.ValidateCredentials(usernameTextBox.Text, passwordTextBox.Text))
                            {
                                bLDAPSuccess = true;
                            }
                        }
                        break;

                    case "DOMAIN":
                        using (var context = new PrincipalContext(ContextType.Domain))
                        {
                            if (context.ValidateCredentials(usernameTextBox.Text, passwordTextBox.Text))
                            {
                                bLDAPSuccess = true;
                            }
                        }
                        break;

                    default:

                        break;
                    }
                }
            }
            catch (Exception excLDAP)
            {
                RiskApps3.Utilities.Logger.Instance.WriteToLog("LDAP Authentication failed for user " + usernameTextBox.Text + " for this reason: " + excLDAP.ToString());
            }
            // end jdg 10/30/15

            String encryptedPassword = RiskAppCore.User.encryptPassword(passwordTextBox.Text);

            bool authenticated     = false;
            int  numFailedAttempts = 0;
            int  numMaxFailures    = 5;
            int  lockoutPeriod     = 0;

            lockoutMsg = "";

            Utilities.ParameterCollection pc = new Utilities.ParameterCollection();
            pc.Add("ntLoginName", DBUtils.makeSQLSafe(ntUser));
            pc.Add("userLogin", DBUtils.makeSQLSafe((u != null) ? u.userLogin : usernameTextBox.Text));

            //if (SessionManager.Instance.MetaData.Globals.encryptPasswords)
            if ((SessionManager.Instance.MetaData.Globals.encryptPasswords) && (!bLDAP))
            {
                pc.Add("userPassword", DBUtils.makeSQLSafe(encryptedPassword));
            }
            else
            {
                pc.Add("userPassword", DBUtils.makeSQLSafe(passwordTextBox.Text));
            }
            // begin jdg 10/30/15
            pc.Add("bLDAP", (bLDAP ? 1 : 0));
            pc.Add("bLDAPSuccess", (bLDAPSuccess ? 1 : 0));
            // end jdg 10/30/15

            SqlDataReader reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_Authenticate_User", pc);

            if (reader != null)
            {
                if (reader.Read())
                {
                    authenticated     = (bool)reader.GetSqlBoolean(0);
                    numFailedAttempts = (int)reader.GetInt32(1);
                    numMaxFailures    = (int)reader.GetInt32(2);
                    lockoutPeriod     = (int)reader.GetInt32(3);
                }
                reader.Close();
            }
            if ((!validUser) || (!authenticated))  //note that if they're not a valid user they won't be authenticated, but we've updated the failed count and timeout values
            {
                if (lockoutPeriod > 0)
                {
                    lockoutMsg = "\r\nLogin attempts will be blocked for " + lockoutPeriod.ToString() + " minute" + ((lockoutPeriod > 1) ? "s." : ".");
                }
                else
                {
                    lockoutMsg = "\r\nYou have made " + numFailedAttempts.ToString() + " failed Login attempt" + ((numFailedAttempts > 1) ? "s" : "") + " of a maximum " + numMaxFailures.ToString() + " allowed.";
                }
            }

            if (validUser && authenticated)
            {
                //see if user is forced to change password
                if (!bLDAP) // jdg 10/30/15
                {
                    if (ApplicationUtils.checkPasswordForceChange(u.userLogin))
                    {
                        String username = usernameTextBox.Text;
                        SessionManager.Instance.MetaData.Users.BackgroundListLoad();
                        passwordTextBox.Text = "";
                        usernameTextBox.Text = username;
                        this.DialogResult    = System.Windows.Forms.DialogResult.None;
                        return;
                    }

                    if (ApplicationUtils.checkPasswordDateOK(u.userLogin) == false)
                    {
                        String username = usernameTextBox.Text;
                        SessionManager.Instance.MetaData.Users.BackgroundListLoad();
                        passwordTextBox.Text = "";
                        usernameTextBox.Text = username;
                        this.DialogResult    = System.Windows.Forms.DialogResult.None;
                        return;
                    }
                }
                roleID   = RiskAppCore.User.fetchUserRoleID(u.userLogin);
                roleName = RiskAppCore.User.fetchUserRoleName(u.userLogin);

                switch (roleName)
                {
                case "Tablet":
                    RiskAppCore.ErrorMessages.Show(RiskAppCore.ErrorMessages.ROLE_ACCESS_DENIED);
                    return;

                default:
                    break;
                }
                SessionManager.Instance.ActiveUser = u;
                InitUserGUIPrefs(u);
                u.UserClinicList.user_login = u.userLogin;
                u.UserClinicList.AddHandlersWithLoad(null, UserClinicListLoaded, null);
                //DialogResult = DialogResult.OK;

                HraObject.AuditUserLogin(u.userLogin);

                stopWatch.Stop();
                // Get the elapsed time as a TimeSpan value.
                TimeSpan ts = stopWatch.Elapsed;
                if (ts.TotalSeconds < requiredSplashTime)
                {
                    progressBar1.Style = ProgressBarStyle.Blocks;
                    progressBar1.Value = progressBar1.Maximum;
                    progressBar1.Refresh();
                    Application.DoEvents();
                    Thread.Sleep((int)(1000 * (requiredSplashTime - ts.TotalSeconds)));
                }

                return;
            }

            if (numFailedAttempts == 1)
            {
                MessageBox.Show(
                    "You have provided an incorrect username or password.\r\nPlease correct your password or try a different user." + lockoutMsg,
                    "Incorrect Username/Password",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            else if (numFailedAttempts > 1)
            {
                MessageBox.Show(
                    lockoutMsg,
                    "Incorrect Username/Password",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            return;
        }
Esempio n. 16
0
        /// <summary>
        /// Checks if its possible to login depending on the given username and password and saves the logged in user to a list
        /// </summary>
        /// <param name="obj"></param>
        private void LoginExecute(object obj)
        {
            string password = (obj as PasswordBox).Password;
            bool   found    = false;
            bool   correct  = false;

            if (UserList.Any())
            {
                for (int i = 0; i < UserList.Count; i++)
                {
                    if (User.JMBG == UserList[i].JMBG && password == "Gost")
                    {
                        Service.loggedUser.Add(UserList[i]);
                        Service.currentUser = UserList[i];

                        if (service.CheckOrderStatus(UserList[i].UserID))
                        {
                            MessageBox.Show("Your order is pending.");
                            Login log = new Login();
                            log.Show();
                            view.Close();
                        }
                        else
                        {
                            if (service.GetOrderStatus(UserList[i].UserID) == "approved")
                            {
                                MessageBox.Show("Your order has been approved");
                                Thread.Sleep(2000);
                            }
                            else if (service.GetOrderStatus(UserList[i].UserID) == "denied")
                            {
                                MessageBox.Show("Your order has been denied");
                                Thread.Sleep(2000);
                            }
                            MainWindow mw = new MainWindow();
                            LabelInfo = "Logged in";
                            found     = true;
                            view.Close();
                            mw.Show();
                            break;
                        }
                        correct = true;
                        found   = true;
                    }
                }

                if (found == false)
                {
                    if (ValidJMBG(User.JMBG) && password == "Gost")
                    {
                        tblUser user = new tblUser();
                        user.JMBG = User.JMBG;
                        service.AddUser(user);

                        Service.currentUser = service.GetUser(User.JMBG);

                        MainWindow mw = new MainWindow();
                        LabelInfo = "Logged in";
                        found     = true;
                        correct   = true;
                        view.Close();
                        mw.Show();
                    }
                }
                if (correct == false)
                {
                    LabelInfo = "Wrong Username or Password";
                }
            }
            else
            {
                LabelInfo = "Database is empty";
            }

            if (User.JMBG == "Zaposleni" && password == "Zaposleni")
            {
                Employee employee = new Employee();
                view.Close();
                employee.Show();
            }
        }