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; }
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; }
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; }