/// <summary> /// Verifies token with verified token /// </summary> /// <param name="token">jwt string</param> /// <returns>principal of jwt</returns> public ClaimsPrincipal VerifyToken(string token) { // create dto with dto LoginDTO loginDTO = new LoginDTO() { Token = token }; // check if token is in blacklist ResponseDTO <Boolean> responseDTO = new LoginGateway().CheckIfTokenOnBlackList(loginDTO); // if not in blacklist if (responseDTO.IsSuccessful == false) { // create handler to verify token JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler(); // convert string to token var jwt = handler.ReadToken(token) as JwtSecurityToken; // get username from token var username = jwt.Claims.First(claim => claim.Type == "UserName").Value; // if token is validated will set the securitytoken to this. SecurityToken validatedToken = null; // validates users return(handler.ValidateToken(token, new Verify().ValidateToken(username), out validatedToken)); } else { throw new Exception(); } }
public Login GetUser(string username, string password) { LoginGateway user = new LoginGateway(); Login userInfo = new Login(); userInfo = user.GetUser(username, password); return(userInfo); }
/// <summary> /// get questions from db /// </summary> /// <returns>the 3 questions for recovery entered during registration</returns> public Outcome Execute() { var response = new Outcome(); var loginGateway = new LoginGateway(); response.Result = loginGateway.GetSecurityQuestions(loginDTO); return(response); }
/// <summary> /// Get user credentials from db /// username, salt, hash pass, type, id /// </summary> /// <returns>returns dto with user credentials</returns> public Outcome Execute() { var response = new Outcome(); LoginGateway loginGateway = new LoginGateway(); response.Result = loginGateway.GetCredentials(loginDTO); return(response); }
/// <summary> /// check answers from user input /// </summary> /// <returns>returns true if correct answers</returns> public Outcome Execute() { var response = new Outcome(); incommingAnswers.Messages = new List <string>(); if (incommingAnswers.Answers == null) { incommingAnswers.isSuccessful = false; response.Result = incommingAnswers; return(response); } var loginGateway = new LoginGateway(); var dbanswers = loginGateway.GetSecurityQandAs(username); if (dbanswers.isSuccessful == false) { incommingAnswers.isSuccessful = false; response.Result = incommingAnswers; return(response); } // hash answers var hashDTO = new HashDTO(); var hash = new HMAC256(); var hashedAnswers = new Dictionary <int, string>(); foreach (var keys in incommingAnswers.Answers.Keys) { hashDTO.Original = incommingAnswers.Answers[keys]; hashedAnswers[keys] = hash.Hash(hashDTO); } foreach (var keys in hashedAnswers.Keys) { if (hashedAnswers[keys] != dbanswers.Answers[keys]) { incommingAnswers.isSuccessful = false; response.Result = incommingAnswers; return(response); } } incommingAnswers.isSuccessful = true; response.Result = incommingAnswers; return(response); }
private bool GenerateSessionForAdmin() { string userCookies = ""; string userSession = ""; if (HttpContext.Current.Request.Cookies["CK_KP_User_Id"] != null) { userCookies = (string)HttpContext.Current.Request.Cookies["CK_KP_User_Id"].Value; } if (HttpContext.Current.Session["KP_User_Id"] != null) { userSession = HttpContext.Current.Session["KP_User_Id"].ToString(); } if (userSession == null || userSession == "") { if (userCookies != null && userCookies != "") { using (LoginGateway objAdmin = new LoginGateway()) { DataTable dtAdmin = objAdmin.Show_AllUsers(Convert.ToInt32(userCookies)); if (dtAdmin.Rows.Count > 0) { HttpContext.Current.Session["KP_User_Id"] = dtAdmin.Rows[0]["UserId"].ToString(); HttpContext.Current.Session["KP_Name"] = dtAdmin.Rows[0]["FullName"].ToString(); HttpContext.Current.Session["KP_UserName"] = dtAdmin.Rows[0]["UserName"].ToString(); HttpContext.Current.Response.Cookies["CK_KP_User_Id"].Expires = DateTime.Now.AddDays(7); return(true); } else { return(false); } } } else { return(false); } } else { return(true); } }
/// <summary> /// adds token and secret to db /// </summary> /// <param name="username">user to get new token</param> /// <param name="jwt">token created</param> /// <param name="secret">secret that has signed token</param> private void AddTokenToDB(string username, string jwt, byte[] secret) { // login gateway use to connect to db LoginGateway loginGateway = new LoginGateway(); // dto that is sent to gateway LoginDTO loginDTO = new LoginDTO() { UserName = username, Token = jwt, Salt = Convert.ToBase64String(secret) }; // adds token to db loginGateway.AddToTokenList(loginDTO); }
/// <summary> /// add token to blacklist /// </summary> /// <returns>isSuccessful = true is added else false</returns> public Outcome Execute() { var response = new Outcome(); LoginDTO loginDTO = new LoginDTO() { UserName = userCredentia.Username, Token = userCredentia.Token }; LoginGateway logoutGateway = new LoginGateway(); response.Result = logoutGateway.AddTokenToBlackList(loginDTO); return(response); }
public bool GivePermitToCandidateToLogin(DAL.DAO.CandidateLogin aCandidateLogin) { LoginGateway aLoginGateway = new LoginGateway(); aLoginGateway.ConfirmConnection(); CandidateLogin bCandidateLogin = new CandidateLogin(); bCandidateLogin = aLoginGateway.CheckCandidateLoginInfo(aCandidateLogin.CandidateName, aCandidateLogin.CandidatePassword); if (bCandidateLogin.CandidateName == aCandidateLogin.CandidateName && bCandidateLogin.CandidatePassword == aCandidateLogin.CandidatePassword) { return(true); } return(false); //bool permitMessage = aLoginGateway.CheckCandidateLoginInfo(aCandidateLogin); //return permitMessage; }
protected void loginButton_Click(object sender, EventArgs e) { LoginClass login = new LoginClass(); LoginGateway loginGateway = new LoginGateway(); DataTable dt = new DataTable(); // try //{ login.UserName = userNameTextBox.Text; login.UserPassword = passwordTextBox.Text; dt = loginGateway.Login(login); if (dt.Rows.Count > 0) { login.UserId = Convert.ToInt32(dt.Rows[0]["UserId"].ToString()); login.UserName = dt.Rows[0]["UserName"].ToString(); login.FullName = dt.Rows[0]["FullName"].ToString(); //login.ZoneName = dt.Rows[0]["ZoneName"].ToString(); if (login.UserId != 0) { //this.Session.Timeout = 300; this.Session["KP_User_Id"] = login.UserId.ToString(); this.Session["KP_UserName"] = login.UserName.ToString(); this.Session["KP_Name"] = login.FullName.ToString(); // this.Session["KP_Zone"] = login.ZoneName.ToString(); Response.Cookies["CK_KP_User_Id"].Value = login.UserId.ToString(); Response.Cookies["CK_KP_User_Id"].Expires = DateTime.Now.AddDays(7); Response.Redirect("Users/UserProfile.aspx", false); } } else { Response.Write("Access denied! Invalid Login Email or Password."); } //Response.Write(dt.Rows.Count); // } //catch (Exception ex){ //Response.Write("error"); //} }
/// <summary> /// get secret from db with username /// </summary> /// <param name="username">username</param> /// <returns>returns secret that signed the jwt</returns> public string UsersSecret(string username) { // gateway LoginGateway auth = new LoginGateway(); //dto to find secret by username LoginDTO dto = new LoginDTO() { UserName = username }; // response dto ResponseDTO <string> response = auth.GetSaltFromTokenList(dto); // return secret return(response.Data); }
public bool GivePermitToLogin(DAL.DAO.AdminLogin aAdminLogin) { LoginGateway aLoginGateway = new LoginGateway(); aLoginGateway.ConfirmConnection(); AdminLogin bAdminLogin = aLoginGateway.CheckLoginInfoTest(aAdminLogin.Username, aAdminLogin.Password); if (bAdminLogin.Username == aAdminLogin.Username && bAdminLogin.Password == aAdminLogin.Password) { return(true); } return(false); //bool permitMessage = aLoginGateway.CheckLoginInfo(aAdminLogin); //return permitMessage; }
public bool GivePermitToVoterToLogin(DAL.DAO.VoterLogin aVoterLogin) { LoginGateway aLoginGateway = new LoginGateway(); aLoginGateway.ConfirmConnection(); VoterLogin bVoterLogin = new VoterLogin(); bVoterLogin = aLoginGateway.CheckVoterLoginInfo(aVoterLogin.VoterID, aVoterLogin.VoterPassword); if (bVoterLogin.VoterID == aVoterLogin.VoterID && bVoterLogin.VoterPassword == aVoterLogin.VoterPassword) { return(true); } return(false); //bool permitMessage = aLoginGateway.CheckVoterLoginInfo(aVoterLogin); //return permitMessage; }
/// <summary> /// refreshes token /// </summary> /// <returns>new token</returns> public TokenRefreshResponseDTO RefreshService() { LoginGateway gateway = new LoginGateway(); LoginDTO incUsername = new LoginDTO() { UserName = username, Token = response.token }; response.Messages = new List <string>(); var storetoken = gateway.AddTokenToBlackList(incUsername); if (storetoken.isSuccessful == false) { response.Messages.Add("Failed to add token"); return(response); } CreateJWT newJWT = new CreateJWT(); var jwt = newJWT.CreateToken(username); if (jwt == "Failed") { response.Messages.Add("Failed To make token"); return(response); } response.token = jwt; response.username = this.username; response.isSuccessful = true; response.Messages.Add("Success!"); return(response); }
/// <summary> /// add token to login gateway /// </summary> /// <param name="userCredential">username and token</param> /// <returns>responseDTO with true or false</returns> public LogoutResponseDTO logout(UserCredential userCredential) { LoginGateway logoutGateway = new LoginGateway(); var addToBlackList = new AddToBlackList() { userCredentia = userCredential }; var response = (LogoutResponseDTO)addToBlackList.Execute().Result; response.Messages = new List <string>(); if (response.isSuccessful == false) { response.Messages.Add("Failed To Logout"); return(response); } response.Messages.Add("Success!"); return(response); }
public UserController(IMapper mapper, LoginGateway loginGateway) { _mapper = mapper; _loginGateway = loginGateway; }
public static List <UsersRegistration> UserLogin() { return(LoginGateway.UserLogin()); }
public LoginManager() { aLoginGateway = new LoginGateway(); }
public static List <Menu> UserMenu(long userId) { return(LoginGateway.UserMenu(userId)); }
/// <summary> /// Set nw password for user /// </summary> /// <returns>return true if successful else false</returns> public Outcome Execute() { var response = new Outcome(); var messages = new List <string>(); ResetPasswordResponseDTO validResponse = new ResetPasswordResponseDTO(); // Returns error if user credentials are null if (incommingCredentials == null) { validResponse.isSuccessful = false; messages.Add(AccountConstants.REGISTRATION_INVALID); validResponse.Messages = messages; response.Result = validResponse; return(response); } var validator = new UserCredValidator(); var results = validator.Validate(incommingCredentials); IList <ValidationFailure> failures = results.Errors; // Returns any error messages if there was any when validating if (failures.Any()) { foreach (ValidationFailure failure in failures) { messages.Add(failure.ErrorMessage); } validResponse.isSuccessful = false; validResponse.Messages = messages; response.Result = validResponse; return(response); } if (new BadPasswordService().BadPassword(incommingCredentials.Password) == true) { validResponse.isSuccessful = false; messages.Add("Bad Password"); validResponse.Messages = messages; response.Result = validResponse; return(response); } HMAC256 hashPassword = new HMAC256(); string newSALT = hashPassword.GenerateSalt(); HashDTO hashDTO = new HashDTO() { Original = incommingCredentials.Password + newSALT }; string newPassword = hashPassword.Hash(hashDTO); LoginDTO newCredentials = new LoginDTO() { UserName = incommingCredentials.Username, Password = newPassword, SaltValue = newSALT }; LoginGateway loginGateway = new LoginGateway(); response.Result = loginGateway.SetNewPass(newCredentials); return(response); }