Example #1
0
        /// <summary>
        /// Alternative login function using the current logged in user on the windows machine.
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool login()
        {
            //Loop through users table.
            Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_UserTableAdapter userTableAdapter = new Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_UserTableAdapter();
            foreach (DataRow row in userTableAdapter.GetData().Rows)
            {
                //Do the usernames match?
                if (row["UserName"].ToString().ToLower() == Environment.UserName.ToLower())
                {
                    //Set userid.
                    ARA_Globals.UserID = (Int32)row["UserID"];

                    //Set permission level.
                    try
                    {
                        Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_User_PermissionsTableAdapter permissionTableAdapter = new Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_User_PermissionsTableAdapter();
                        ARA_Globals.UserPermissionGroup = permissionTableAdapter.GetData().FindByPermissionID((Int32)row["PermissionID"])["PermissionName"].ToString();
                        ARA_Globals.LoggedInUsername    = Environment.UserName;
                    }
                    catch (Exception)
                    {
                        //We didnt get his permission level, set it to default.
                        ARA_Globals.UserPermissionGroup = "Default";
                    }
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// Gets users table out of database and tries too compare the users login data.
        /// </summary>
        /// <param name="username">Users username.</param>
        /// <param name="passwordHash">A hash representing the users password.</param>
        /// <returns></returns>
        public bool login(string username, byte[] passwordHash)
        {
            //Loop through users table.
            Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_UserTableAdapter userTableAdapter = new Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_UserTableAdapter();
            foreach (DataRow row in userTableAdapter.GetData().Rows)
            {
                //Do the usernames match?
                if (row["UserName"].ToString() == username)
                {
                    //Does his password match?
                    if (compareHashes((byte[])row["PasswordHash"], passwordHash))
                    {
                        //Set userid.
                        ARA_Globals.UserID = (Int32)row["UserID"];

                        //Set permission level.
                        try
                        {
                            Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_User_PermissionsTableAdapter permissionTableAdapter = new Applicatie_Risicoanalyse.LG_Analysis_DatabaseDataSetTableAdapters.Tbl_User_PermissionsTableAdapter();
                            ARA_Globals.UserPermissionGroup = permissionTableAdapter.GetData().FindByPermissionID((Int32)row["PermissionID"])["PermissionName"].ToString();
                        }
                        catch (Exception)
                        {
                            //We didnt get his permission level, set it to default.
                            ARA_Globals.UserPermissionGroup = "Default";
                        }
                        return(true);
                    }
                    return(false);
                }
            }
            return(false);
        }