public static AuthUserX CheckAuthentication(IDbContext db, string username, string password, bool passwordIsHashed = false) { string hash; if (passwordIsHashed) { hash = password; } else { hash = AuthUserDBExtention.GetHash(password); } string ip = null; //TODO AuthUserX user = db.Find <AuthUserX>(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true).FirstOrDefault(); if (user != null && (string.IsNullOrEmpty(user.RestrictedIP) || ip == user.RestrictedIP)) { db.Save(new LoginLog { Sucess = true, UserId = user.Id, Username = user.Username, IP = ip }); return(user); } db.Save(new LoginLog { Sucess = false, Username = username, IP = ip }); return(null); }
public static AuthUserX CheckAuthentication(this IDbContext db, string username, string password, bool passwordIsHashed = false) { string hash; if (passwordIsHashed) { hash = password; } else { hash = AuthUserDBExtention.GetHash(password); } string ip = null; //TODO var user = db.FindFirst <AuthUserX>(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true); if (user != null) { db.Save(new LoginLog { Sucess = true, UserId = user.Id, Username = user.Username, IP = ip }); return(user); } db.Save(new LoginLog { Sucess = false, Username = username, IP = ip }); return(null); }
public async Task <IActionResult> ChangePassword(ChangePasswordVM model) { var user = userCol.FindFirst(u => u.Id == UserId); if (user != null) { if (AuthUserDBExtention.GetHash(model.CurrentPassword) == user.HashedPassword) { if (model.NewPassword == model.RepeatNewPassword) { user.Password = model.NewPassword; await userCol.InsertOneAsync(user); return(Ok()); } else { return(BadRequest("رمز جدید و تکرار آن باهم برابر نیستند.")); } } else { return(BadRequest("رمز فعلی اشتباه میباشد.")); } } return(Unauthorized()); }
public IActionResult ChangePassword(ChangePasswordVM model) { var user = db.FindFirst <AuthUserX>(u => u.Id == UserId); if (user != null) { if (AuthUserDBExtention.GetHash(model.CurrentPassword) == user.HashedPassword) { if (model.NewPassword == model.RepeatNewPassword) { user.Password = model.NewPassword; db.Save(user); return(Ok()); } else { return(BadRequest("رمز جدید و تکرار آن باهم برابر نیستند.")); } } else { return(BadRequest("رمز فعلی اشتباه میباشد.")); } } return(Unauthorized()); }
public static AuthUserX CheckAuthentication(this IMongoCollection <AuthUserX> userCol, string username, string password, bool passwordIsHashed = false) { string hash; if (passwordIsHashed) { hash = password; } else { hash = AuthUserDBExtention.GetHash(password); } return(userCol.FindFirst(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true)); }
public static AuthUserX CheckAuthentication(this IDbContext DB, string username, string password, bool passwordIsHashed = false) { string hash; if (passwordIsHashed) { hash = password; } else { hash = AuthUserDBExtention.GetHash(password); } return(DB.FindFirst <AuthUserX>(u => u.Username == username && u.HashedPassword == hash && u.Disabled != true)); }