Exemplo n.º 1
0
        public Users GetAuthenticatedUsers()
        {
            var users = new Users();

            var user = new User("testuser", 10);
            user.HostMask = "testhostmask";
            users.AddUser(user);

            return users;
        }
        public User LogInUser(string userName, string password)
        {
            // Reads the xml-file and creates a dataset
            System.Data.DataSet dsUsers = new System.Data.DataSet();
            dsUsers.ReadXml(this.configDirectory + settingsReader.GetValue("UsersConfigXml", typeof(string)).ToString());
            foreach (System.Data.DataRow dr in dsUsers.Tables[0].Rows)
            {
                // Lets read the username in the datarow
                string tmpUserName = dr["name"].ToString().ToLower();
                // If the username matches, lets check the password
                if (tmpUserName.Equals(userName.ToLower()))
                {
                    string tmpPassword = dr["password"].ToString().ToUpper();
                    if (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5").Equals(tmpPassword))
                    {
                        // Given username and password was correct. Lets read user's securitylevel
                        int securityLevelID = Int32.Parse(dr["securitylevel_id"].ToString());

                        // Lets create the securitylevel-object
                        SecurityLevel securityLevel = this.GetSecurityLevelByID(securityLevelID);

                        // We get user's id
                        int userID = Int32.Parse(dr["user_id"].ToString());

                        // And then finally we create the user object
                        User newUser = new User(userID, userName, securityLevel);

                        return newUser;
                    }
                }
            }
            // Username and password were incorrect
            return new User("", 0);
        }