Esempio n. 1
0
        public void Login_Test(string username, bool isvalid)
        {
            var password = "******";
            var dt       = (username == "100")
        ? CreateDataTable(new List <Dictionary <string, string> >
            {
                {
                    new Dictionary <string, string>
                    {
                        { nameof(username), "100" },
                        { nameof(password), password },
                    }
                }
            })
        : new DataTable();

            var sqlMock = GetSqlHelperBase(dt);

            loginModule = new LoginModule(sqlMock);

            if (isvalid)
            {
                loginModule.UserLogin(username, password);
            }
            else
            {
                Assert.Throws <Exception>(() => loginModule.UserLogin(username, password));
            }
        }
Esempio n. 2
0
        /// <summary>Calls when a process requests authorization.</summary>
        /// <param name="actionContext">The action context, which encapsulates information for using <see cref="T:System.Web.Http.Filters.AuthorizationFilterAttribute" />.</param>
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }
            else
            {
                try
                {
                    var auth = Encoding.UTF8
                               .GetString(Convert.FromBase64String(actionContext.Request.Headers.Authorization.Parameter)).Split(':');

                    auth.ToList().ForEach(x => BasicValidator.ValidateAsNonSpacedString(x, errorLogger));

                    var username = auth[0];
                    var password = auth[1];

                    var login = new LoginModule(new SqlHelperBase(errorLogger));

                    if (login.UserLogin(username, password))
                    {
                        Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), null);
                    }
                    else
                    {
                        actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
                    }
                }
                catch (Exception e)
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
                }
            }
        }
Esempio n. 3
0
        protected void login_Click(object sender, EventArgs e)
        {
            var username = this.username.Text;
            var password = this.password.Text;

            if (loginModule.UserLogin(username, password))
            {
                this.Session["EmpNr"] = username;
                this.Response.Redirect("TimeTracking.aspx");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Username or Password is invalid');", true);
            }
        }