示例#1
0
        public virtual void UpdateUser(SqlUser user, string[] allDatabases)
        {
            if (user.Databases == null)
            {
                user.Databases = new string[0];
            }

            // update user databases access
            string[] databases = GetUserDatabases(user.Name);
            foreach (string database in databases)
            {
                RemoveUserFromDatabase(database, user.Name);
            }

            foreach (string database in user.Databases)
            {
                AddUserToDatabase(database, user.Name);
            }

            // change user password if required
            if (!String.IsNullOrEmpty(user.Password))
            {
                ChangeUserPassword(user.Name, user.Password);
            }
        }
示例#2
0
        public override void CreateUser(SqlUser user, string password)
        {
            if (user.Databases == null)
            {
                user.Databases = new string[0];
            }

            /*if (!((Regex.IsMatch(user.Name, @"[^\w\.-]")) && (user.Name.Length > 16)))
             * {
             *  Exception ex = new Exception("INVALID_USERNAME");
             *  throw ex;
             * }
             */
            ExecuteNonQuery(String.Format(
                                "CREATE USER '{0}'@'%' IDENTIFIED BY '{1}'",
                                user.Name, password));

            if (OldPassword)
            {
                ChangeUserPassword(user.Name, password);
            }

            // add access to databases
            foreach (string database in user.Databases)
            {
                AddUserToDatabase(database, user.Name);
            }
        }
示例#3
0
        public virtual SqlUser GetUser(string username, string[] databases)
        {
            // get user information
            SqlUser user = new SqlUser();

            user.Name = username;

            // get user databases
            user.Databases = GetUserDatabases(username);

            return(user);
        }