Esempio n. 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var loginWindow    = new LoginWindow();
            var authentication = new UserAuthentication();

            while (true)
            {
                if ((loginWindow.ShowDialog() != DialogResult.OK))
                {
                    return;
                }
                var user = authentication.Authenticate(loginWindow.Login, loginWindow.Password);
                if (user != null)
                {
                    Application.Run(new EmployeeMonitoringSystem(user));
                    return;
                }
                else
                {
                    MessageBox.Show("Wrong username or password");
                }
            }
        }
Esempio n. 2
0
        public LoginResponse Login([FromBody] Login login)
        {
            LoginResponse resp = UserAuthentication.Authenticate(login);

            if (resp != null)
            {
                return(resp);
            }

            return(new LoginResponse());
        }
Esempio n. 3
0
        public IActionResult Authenticate([FromBody] UserDTO userParam)
        {
            var user = _userAuthentication.Authenticate(userParam.Username, userParam.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(user));
        }
        public IActionResult CreateToken([FromBody] UserLogin login)
        {
            IActionResult response = Unauthorized();
            var           user     = UserAuthentication.Authenticate(login);

            if (user != null)
            {
                var tokenString = UserAuthentication.BuildToken(user);
                response = Ok(new { token = tokenString });
            }

            return(response);
        }
        public async Task <HttpResponseMessage> PostChangePassword([FromBody] ChangePassword changePass)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Model State"));
                }
                if (!emailvalidator.IsMatch(changePass.PrimaryEmail.Trim()))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid PrimaryEmail"));
                }

                Login login = new Login()
                {
                    Email    = changePass.PrimaryEmail,
                    Password = changePass.CurrentPassword
                };
                LoginResponse resp = UserAuthentication.Authenticate(login);
                if (resp == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.Conflict, "Current password is invalid. Try again or request a new temporary password."));
                }

                UserAccountSecurityManager resetter = new UserAccountSecurityManager();

                bool rval = await resetter.ChangePassword(changePass);

                if (rval)
                {
                    resp.PasswordResetRequired = false;
                    await db.SaveChangesAsync();

                    return(Request.CreateResponse(HttpStatusCode.OK, "Created Successfully"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Unknown error"));
                }
            }
            catch (CSETApplicationException ce)
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, ce.Message));
            }
            catch (Exception e)
            {
                return(CSETWeb_Api.Helpers.ElmahWrapper.LogAndReportException(e, Request, HttpContext.Current));
            }
        }
Esempio n. 6
0
    public static void UserOptions()
    {
        //Console.Clear();
        // Console.WriteLine("Please pick a program:"
        // + "\n1: User Data"
        // + "\n2: User Authentication"
        // + "\n3: Loop Counting");

        Console.WriteLine(@"Please pick a program: 
1: User Data
2: User Authentication
3: Loop Counting
4: Student Manager
");

        var selectedOption = Console.ReadLine();

        // Check if the user entered an empty string. If they did then call UserOptions again. Keep doing this until the user enters a correct option.
        while (selectedOption == "")
        {
            UserOptions();
        }

        switch (selectedOption)
        {
        case "1":
            UserData.Ask();
            break;

        case "2":
            UserAuthentication.Authenticate();
            break;

        case "3":
            LoopCounting.Count();
            break;

        case "4":
            StudentManager.studentManager();
            break;

        default:
            UserOptions();
            break;
        }
    }
Esempio n. 7
0
        public void Authenticate(string username, string password)
        {
            UserAuthentication.Authenticate(this, username, password);

            this.RequestDigest = UserAuthentication.GetRequestDigest(this);
        }