//Authentication //Input: loginDTO //Output: client public static client checkUserLogin(loginDTO body) { SwapDbConnection db = new SwapDbConnection(); client user = db.clients.FirstOrDefault(x => x.email == body.email && x.platform == "local"); if (user == null || !HashSalt.VerifyPassword(body.password, user.password, user.salt)) { return(null); } user.last_login = DateTime.Now; db.SaveChanges(); return(user); }
//Generate new password //Input: id, password //Output: string result public static string NewPassword(string id, string password) { SwapDbConnection db = new SwapDbConnection(); client client = db.clients.FirstOrDefault(c => c.client_id == id); HashSalt hashSalt; if (client == null || client.platform != "local") { return("false"); } if (HashSalt.VerifyPassword(password, client.password, client.salt)) { return("same"); } hashSalt = HashSalt.GenerateSaltedHash(password); client.password = hashSalt.Hash; client.salt = hashSalt.Salt; db.SaveChanges(); return("ok"); }