Example #1
0
 // 保存一个密码
 public static void SavePassword(string uid,
                                 string userName,
                                 string password)
 {
     lock (_passwordTable.SyncRoot)
     {
         string       key  = PasswordItem.BuildKey(uid, userName);
         PasswordItem item = (PasswordItem)_passwordTable[key];
         if (item == null)
         {
             item = new PasswordItem
             {
                 UID      = uid,
                 UserName = userName,
                 Password = password,
                 LastTime = DateTime.Now
             };
             _passwordTable[key] = item;
         }
         else
         {
             item.Password = password;
             item.LastTime = DateTime.Now;
         }
     }
 }
Example #2
0
 // 从缓存中删掉一个密码事项
 public static void DeletePassword(string uid, string userName)
 {
     lock (_passwordTable.SyncRoot)
     {
         string key = PasswordItem.BuildKey(uid, userName);
         _passwordTable.Remove(key);
     }
 }
Example #3
0
 // 获取一个密码
 // return:
 //      null    没有找到密码
 //      其它  返回密码
 public static string GetPassword(string uid, string userName)
 {
     lock (_passwordTable.SyncRoot)
     {
         string       key  = PasswordItem.BuildKey(uid, userName);
         PasswordItem item = (PasswordItem)_passwordTable[key];
         if (item == null)
         {
             return(null);
         }
         item.LastTime = DateTime.Now;
         return(item.Password);
     }
 }