示例#1
0
        public static void search(string user, UserDb.search_cb bob, object obj)
        {
            int h = 0;

            while (h < UserDb.maxhash && UserDb.search_one(UserDb.fname(h), user, bob, obj))
            {
                ++h;
            }
        }
示例#2
0
        public static bool delete(string user)
        {
            bool flag = false;

            user = user.ToLower();
            string str = UserDb.fname(user) + ".new";

            lock (UserDb.mylock)
            {
                StreamReader streamReader;
                StreamWriter streamWriter;
                try
                {
                    streamReader = new StreamReader(UserDb.fname(user));
                    streamWriter = new StreamWriter(str);
                }
                catch
                {
                    return(false);
                }
                while (true)
                {
                    string line;
                    User   user1;
                    do
                    {
                        line = streamReader.ReadLine();
                        if (line != null)
                        {
                            user1 = UserDb.read_line(line);
                        }
                        else
                        {
                            goto label_9;
                        }
                    }while (user1 == null);
                    if (user1.user == user)
                    {
                        flag = true;
                    }
                    else
                    {
                        streamWriter.WriteLine(line);
                    }
                }
label_9:
                streamReader.Close();
                streamWriter.Close();
                File.Delete(UserDb.fname(user));
                File.Move(str, UserDb.fname(user));
            }
            return(flag);
        }
示例#3
0
        public static bool add(
            string user,
            string passwd,
            NameValueCollection info,
            string oldpassword,
            out string reason)
        {
            user = user.ToLower();
            bool flag = false;

            reason = "none";
            UserDb.uid_get(user);
            if (passwd.Length == 0)
            {
                flag = true;
            }
            passwd = !flag?UserDb.encode_passwd(user, passwd) : oldpassword;

            lock (UserDb.mylock)
            {
                StreamWriter streamWriter;
                try
                {
                    streamWriter = new StreamWriter(UserDb.fname(user), true);
                }
                catch (Exception ex)
                {
                    clib.imsg("userdb: add write {0}", (object)ex.ToString());
                    Directory.CreateDirectory(UserDb.root);
                    try
                    {
                        streamWriter = new StreamWriter(UserDb.fname(user));
                    }
                    catch
                    {
                        reason = "Write to file failed " + ex.Message;
                        clib.imsg("userdb: add write {0}", (object)ex.ToString());
                        return(false);
                    }
                }
                User user1 = new User(user, passwd, info);
                streamWriter.WriteLine(user1.ToString());
                streamWriter.Close();
                return(true);
            }
        }
示例#4
0
        public static User lookup(string user)
        {
            User user1 = (User)null;

            user = user.ToLower();
            StreamReader streamReader;

            try
            {
                streamReader = new StreamReader(UserDb.fname(user));
            }
            catch
            {
                return((User)null);
            }
            while (true)
            {
                User user2;
                do
                {
                    string line = streamReader.ReadLine();
                    if (line != null)
                    {
                        user2 = UserDb.read_line(line);
                    }
                    else
                    {
                        goto label_6;
                    }
                }while (user2 == null || user2.user != user);
                user1 = user2;
            }
label_6:
            streamReader.Close();
            return(user1);
        }
示例#5
0
 private static string fname(string user)
 {
     return(UserDb.fname(UserDb.hash(user)));
 }