Example #1
0
 public static void Logout()
 {
     User.IsLoggedIn = false;
     User.LoggedInUser = null;
 }
Example #2
0
        /// <summary>
        /// Get all the users
        /// </summary>
        /// <returns></returns>
        public static List<User> GetUserList(string userName, string password)
        {
            OleDbConnection connection = new OleDbConnection(global::ResultManagement.Properties.Settings.Default.ConnectionString);

            String cmdStr = @"SELECT     user_id, username, password, authenticated 
                         FROM  `user`  WHERE  1 ";

            if (userName != null)
            {
                cmdStr += " AND  username = '******'";
            }

            if (password != null)
            {
                cmdStr += " AND  password = '******'";
            }

            OleDbCommand cmd = new OleDbCommand(cmdStr, connection);

            List<User> userList = new List<User>();

            try
            {
                connection.Open();
                OleDbDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    User user = new User();

                    user.userId = (int)reader.GetValue(reader.GetOrdinal("user_id"));
                    user.userName = (string)reader.GetValue(reader.GetOrdinal("username"));
                    user.password = (string)reader.GetValue(reader.GetOrdinal("password"));
                    //user.fullName = (string)reader.GetValue(reader.GetOrdinal("full_name"));
                    //user.type = (UserType)reader.GetValue(reader.GetOrdinal("type"));
                    user.authenticated = (bool)reader.GetValue(reader.GetOrdinal("authenticated"));
                    //user.date = (DateTime)reader.GetValue(reader.GetOrdinal("date"));
                    
                    userList.Add(user);
                }
                
            }
            finally
            {
                connection.Close();
            }

            return userList;

        }
Example #3
0
        //**********************************************************

        /// <summary>
        /// Authenticate username and password
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public static void Login(string userName, string password)
        {
            try
            {
                List<User> userList = User.GetUserList(userName, password);

                if (userList.Count > 0)
                {
                    if (userList[0].authenticated)
                    {
                        User.IsLoggedIn = true;
                        User.LoggedInUser = userList[0];
                    }
                    else
                    {
                        MessageBox.Show("Your request has not yet been approved!");
                    }
                }
                else
                {
                    MessageBox.Show("Invalid username & password!");
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }