コード例 #1
0
        protected void authenticate(object sender, EventArgs e)
        {
            string session = "undefined";

            if (!username.Text.Equals("") && !password.Text.Equals(""))
            {
                DataRepository repo = new DataRepository();
                if (repo.checkCredentials(username.Text, password.Text))
                {
                    string[] shortUsername = username.Text.Split('.');

                    session = $"{shortUsername[0]}";
                    byte[] encodedPassword = new UTF8Encoding().GetBytes(session);
                    byte[] hash            = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword);
                    string encoded         = BitConverter.ToString(hash)
                                             .Replace("-", string.Empty)
                                             .ToLower();

                    AuthenticatedUser user = new AuthenticatedUser();
                    user.setSessionId(encoded)
                    .setUsername(username.Text)
                    .setAuthenticatedRole(repo.getRoleFromUsername(username.Text));

                    this.Session["UserAuth"] = user;

                    authRequired.Controls.Clear();
                    authRequired.InnerHtml = $"Laden Sie die Seite neu, um die Anmeldung abzuschließen.";
                    Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
                }
                else
                {
                    invalid.Visible = true;
                }
            }
            else
            {
                enterPassword.Visible = true;
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string session = "undefined";

            if (this.Session["UserAuth"] != null)
            {
                authRequired.Visible = false;
                auth.Visible         = true;
                MainContent.Visible  = true;
                shortcuts.Visible    = true;
                pleaseNote.Visible   = false;

                AuthenticatedUser user = (AuthenticatedUser)this.Session["UserAuth"];
                session = $"{user.getUsername()} ({user.getSessionId()})";
                displayName.InnerText = $"{user.getUsername()} ({user.getAuthenticatedRole().ToString()})";
                if (user.isUser())
                {
                    pleaseNote.Visible = true;
                }
            }
            else
            {
                authRequired.Visible = true;
                auth.Visible         = false;
                MainContent.Visible  = false;
                shortcuts.Visible    = false;
            }

            if (Global.isFirstRun)
            {
                firstRun.Visible = true;
            }

            SessionText.InnerText = session;
            this.checkLifecycle();
        }
コード例 #3
0
 public AuthenticatedUser(AuthenticatedUser user)
 {
     this.setUserId(user.getId());
     this.setUsername(user.getUsername());
     this.setAuthenticatedRole(user.getAuthenticatedRole());
 }