예제 #1
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);
            }
        }
예제 #2
0
 public static int uid_get(string user)
 {
     return(UserDb.uid_get(user));
 }