protected override bool Execute() { if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); ActiveDirectory_DTO adDto = adAdo.GetUser(Ado, DTO); dynamic adUser = adAdo.GetAdSpecificDataForEmail(DTO.CcnEmail); if (adUser?.CcnEmail != null) { DTO.CcnEmail = adUser.CcnEmail; DTO.CcnDisplayname = adUser.CcnDisplayName; DTO.CcnUsername = adUser.CcnUsername; } else { Account_ADO aAdo = new Account_ADO(); var user = aAdo.Read(Ado, new Account_DTO_Read() { CcnUsername = DTO.CcnEmail }); if (!user.hasData) { Response.data = JSONRPC.success; return(true); } if (user.data[0].CcnEmail.Equals(DBNull.Value) || user.data[0].CcnDisplayName.Equals(DBNull.Value)) { Response.data = JSONRPC.success; return(true); } DTO.CcnDisplayname = user.data[0].CcnDisplayName; DTO.CcnEmail = user.data[0].CcnEmail; DTO.CcnUsername = DTO.CcnEmail; } Login_BSO lBso = new Login_BSO(Ado); ADO_readerOutput output = lBso.ReadByToken2Fa(DTO.LgnToken2Fa, DTO.CcnUsername); if (!output.hasData) { return(false); } //create a 2fa, save it to the database, unlock the account and send the 2fa back to the client to be displayed as a QRCode string token = lBso.Update2FA(new Login_DTO_Create2FA() { LgnToken2Fa = DTO.LgnToken2Fa, CcnUsername = DTO.CcnUsername }); Response.data = token; return(true); }
protected override bool Execute() { if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } Login_BSO lBso = new Login_BSO(Ado); Account_ADO aAdo = new Account_ADO(); ADO_readerOutput responseUser = aAdo.Read(Ado, DTO.CcnEmail); //If this is an AD user using their email as an identifier then we must get their details from AD if (!responseUser.hasData) { ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); var adResult = adAdo.GetAdSpecificDataForEmail(DTO.CcnEmail); if (adResult == null) { Response.error = Label.Get("error.authentication"); return(false); } //Check if AD local access is allowed if (!Configuration_BSO.GetCustomConfig(ConfigType.global, "security.adOpenAccess") && adResult != null) { Response.error = Label.Get("error.authentication"); return(false); } DTO.CcnUsername = adResult.CcnUsername; } else { DTO.CcnUsername = responseUser.data[0].CcnUsername; } var response = lBso.Update2FA(DTO); if (response != null) { Response.data = response; return(true); } Response.error = Label.Get("error.authentication"); return(false); }
protected override bool Execute() { ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); dynamic adDto = adAdo.GetAdSpecificDataForEmail(DTO.CcnEmail); if (adDto?.CcnUsername != null) { Response.error = Label.Get("error.authentication"); return(false); } if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } Login_BSO lBso = new Login_BSO(Ado); var userResponse = lBso.ReadByToken1Fa(DTO.LgnToken1Fa, DTO.CcnEmail); if (userResponse.hasData) { string user = userResponse.data[0].CcnUsername; DTO.CcnUsername = user; if (lBso.Update1FA(new Login_DTO_Create1FA() { LgnToken1Fa = DTO.LgnToken1Fa, Lgn1Fa = DTO.Lgn1Fa, CcnEmail = DTO.CcnEmail }, DTO.LgnToken1Fa)) { Response.data = JSONRPC.success; return(true); } } Response.error = Label.Get("error.authentication"); return(false); }
/// <summary> /// Execute /// </summary> /// <returns></returns> protected override bool Execute() { Stopwatch sw = new Stopwatch(); sw.Start(); if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); dynamic adUser = adAdo.GetAdSpecificDataForEmail(DTO.CcnEmail); //Check if local access is available for AD users if (!Configuration_BSO.GetCustomConfig(ConfigType.global, "security.adOpenAccess") && adUser != null) { Response.error = Label.Get("error.authentication"); return(false); } DTO.CcnUsername = DTO.CcnEmail; Login_BSO lBso = new Login_BSO(Ado); Account_ADO aAdo = new Account_ADO(); ADO_readerOutput response = aAdo.Read(Ado, DTO.CcnEmail); string user; if (!response.hasData) { //Email address not in the login table, try to get the username from the email address via AD var adResult = adAdo.GetAdSpecificDataForEmail(DTO.CcnEmail); Log.Instance.Debug("AD user found from email - time ms: " + sw.ElapsedMilliseconds); if (adResult == null) { Response.error = Label.Get("error.authentication"); return(false); } user = adResult.CcnUsername; //Now get the user details from the table response = aAdo.Read(Ado, user); if (!response.hasData) { Response.error = Label.Get("error.authentication"); return(false); } if (response.data[0].CcnLockedFlag) { Response.error = Label.Get("error.account.locked"); return(false); } } else { user = response.data[0].CcnUsername; } if (response.data[0].Lgn2Fa.Equals(DBNull.Value)) { Response.error = Label.Get("error.authentication"); return(false); } if (response.data[0].CcnLockedFlag) { Response.error = Label.Get("error.authentication"); return(false); } int ccnId = response.data[0].CcnId; string login2Fa = response.data[0].Lgn2Fa; if (!API.TwoFA.Validate2fa(DTO.Totp, login2Fa)) { Response.error = Label.Get("error.authentication"); return(false); } response = lBso.Validate1Fa(DTO.Lgn1Fa, user); if (!response.hasData) { //No validation available via the Login table, try Active Directory long lValidatePassword = sw.ElapsedMilliseconds; if (!ActiveDirectory.IsPasswordValid(user, DTO.Lgn1Fa)) { Response.error = Label.Get("error.authentication"); return(false); } Log.Instance.Debug("Elaspsed time ValidatePassword: "******"AD validation time ms: " + sw.ElapsedMilliseconds); //Get the remaining details from the database response = aAdo.Read(Ado, user); if (!response.hasData) { Response.error = Label.Get("error.authentication"); return(false); } } //If we have found an account, credentials are ok, but the account is locked, then we return an account locked error //could be AD too //IsUserAuthenticated needs to check if the user is locked too if (response.data[0].CcnLockedFlag) { Response.error = Label.Get("error.account.locked"); return(false); } string sessionToken = Utility.GetRandomSHA256(ccnId.ToString()); DateTime expiry = DateTime.Now.AddSeconds(Configuration_BSO.GetCustomConfig(ConfigType.global, "session.length")); if (!lBso.CreateSession(sessionToken, expiry, user)) { Response.error = Label.Get("error.create"); return(false); } Response.sessionCookie = new HttpCookie(API.Common.SessionCookieName) { Value = sessionToken }; Response.data = API.JSONRPC.success; long l = sw.ElapsedMilliseconds; return(true); }
protected override bool Execute() { //Validate against ReCAPTCHA if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } //get the user from the token while checking the token is still valid // generate a new token and new timeout //update TD_LOGIN with the hashed password, the new token and the new timeout bool success = false; Login_BSO lBso = new Login_BSO(Ado); var userdata = lBso.ReadByToken1Fa(DTO.LgnToken1Fa, DTO.CcnUsername); if (!userdata.hasData) { Response.error = Label.Get("error.authentication"); return(false); } string newToken = Utility.GetRandomSHA256(userdata.data[0].CcnId.ToString()); DTO.CcnEmail = userdata.data[0].CcnEmail; DTO.CcnUsername = userdata.data[0].CcnUsername; //Not allowed for AD users ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); ActiveDirectory_DTO adDto = adAdo.GetUser(Ado, DTO); if (adDto.CcnDisplayName != null) { Response.error = Label.Get("error.authentication"); return(false); } if (lBso.Update1FA(DTO, newToken)) { DTO.LgnToken1Fa = newToken; lBso.UpdateInvitationToken2Fa(DTO.CcnUsername, newToken); if (sendMail) { SendEmail(new Login_DTO_Create() { CcnUsername = DTO.CcnUsername, LngIsoCode = DTO.LngIsoCode, CcnEmail = DTO.CcnEmail, CcnDisplayname = userdata.data[0].CcnDisplayName }, newToken, "PxStat.Security.Login_API.Create2FA"); } Response.data = JSONRPC.success; success = true; } else { Response.error = Label.Get("error.create"); success = false; } return(success); }
public ReCAPTCHAService(IOptions <ReCAPTCHA> options) { _reCAPTCHA = options.Value; }
/// <summary> /// Execute /// </summary> /// <returns></returns> protected override bool Execute() { if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } if (DTO.CcnUsername == null) { DTO.CcnUsername = DTO.CcnEmail; } //Not allowed for AD users ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); ActiveDirectory_DTO adDto = adAdo.GetUser(Ado, DTO); if (adDto.CcnDisplayName != null) { Response.data = JSONRPC.success; return(true); } Account_ADO ccnAdo = new Account_ADO(); var user = ccnAdo.Read(Ado, new Account_DTO_Read() { CcnUsername = DTO.CcnEmail }); if (!user.hasData) { Response.data = JSONRPC.success; return(true); } if (user.data[0].CcnEmail.Equals(DBNull.Value) || user.data[0].CcnDisplayName.Equals(DBNull.Value)) { Response.data = JSONRPC.success; return(true); } DTO.CcnEmail = user.data[0].CcnEmail; Login_BSO lBso = new Login_BSO(Ado); string loginToken = Utility.GetRandomSHA256(user.data[0].CcnId.ToString()); Login_DTO_Create ldto = new Login_DTO_Create() { CcnUsername = DTO.CcnEmail, LngIsoCode = DTO.LngIsoCode, CcnEmail = DTO.CcnEmail, CcnDisplayname = user.data[0].CcnDisplayName }; if (lBso.Update1FaTokenForUser(DTO.CcnEmail, loginToken) != null) { SendEmail(new Login_DTO_Create() { CcnUsername = user.data[0].CcnUsername, LngIsoCode = DTO.LngIsoCode, CcnEmail = user.data[0].CcnEmail, CcnDisplayname = user.data[0].CcnDisplayName }, loginToken, "PxStat.Security.Login_API.Update1FA"); Response.data = JSONRPC.success; return(true); } else { Response.error = Label.Get("error.create"); return(false); } }