开发者

how to allow login in with email using the asp signup component

as the title says how do o allow users to sign in using the email they specified when they registered.

using asp 3.5 , both the lo开发者_Go百科gin and signup are the ones that are built-in visual studio.

also is there a way to remove the secret question and answer.

thanks


My simplest and effective workaround for this was to do the following:

1- Rename the label of username field as E-mail: ( so the user will see it Email, but it's actually still the username that ASP.NET membership will save).

2- Save my entry normally along side with any additional info I need to save

3- now my users will be forced to login using their provided Email

4- Smile :)


I think you are looking for forms authentication. There are alot of instructions on google. Or see here: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.aspx

You need to wire up the control's login click event to your authentication logic,

    protected void Login_Click(object sender, EventArgs e)
    {  
        // your logic here 
    }

Also something like the following should go into Global.asax.cs to create an authentication ticket (cookie) that represents the users authenticated session.

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        String cookieName = FormsAuthentication.FormsCookieName;
        HttpCookie authCookie = Context.Request.Cookies[cookieName];

        if (null == authCookie)
        {//There is no authentication cookie.
            return;
        }

        FormsAuthenticationTicket authTicket = null;

        try
        {
            authTicket = FormsAuthentication.Decrypt(authCookie.Value);
        }
        catch (Exception ex)
        {
            //Write the exception to the Event Log.
            return;
        }

        if (null == authTicket)
        {//Cookie failed to decrypt.
            return;
        }

        //When the ticket was created, the UserData property was assigned a
        //pipe-delimited string of group names.
        String[] groups = authTicket.UserData.Split(new char[] { '|' });

        //Create an Identity.
        GenericIdentity id = new GenericIdentity(authTicket.Name, "LdapAuthentication");

        //This principal flows throughout the request.
        GenericPrincipal principal = new GenericPrincipal(id, groups);

        Context.User = principal;
    }

You will also need an 'IsAuthenticted' boolean method to contain the logic of authentication. In your case you need store their e-mail addresses somewhere and point your authentication logic at that source.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜