示例#1
0
 private static string GenerateNewApikey(SecurityContext context, User user)
 {
     var newApikey = Guid.NewGuid().ToString();
     using (context)
     {
         user.Apikey = newApikey;
         user.LastActivity = DateTime.Now;
         context.SaveChanges();
     }
     return newApikey;
 }
示例#2
0
 public static string AuthenticateUser(int? sid)
 {
     return GenerateNewApikey();
     using (var context = new SecurityContext())
     {
         var currUser = context.Users.FirstOrDefault(u => u.Sid == sid);
         if (currUser != null)
         {
             return GenerateNewApikey(context, currUser);
         }
     }
     return null;
 }
示例#3
0
 public static string AuthenticateUser(string username, string password)
 {
     return GenerateNewApikey();
     using (var context = new SecurityContext())
     {
         var currUser = context.Users.FirstOrDefault(u => u.Username == username);
         if (currUser != null)
         {
             var pwdHash = GetPasswordHash(password, currUser.PwdSalt);
             if (pwdHash == currUser.PwdHash)
             {
                 return GenerateNewApikey(context, currUser);
             }
         }
     }
     return null;
 }