Need help for using <asp:Login /> control

Last post 12-30-2005 12:38 AM by Bindu. 3 replies.

Sort Posts:

  • Need help for using <asp:Login /> control

    12-29-2005, 3:06 AM
    • Member
      425 point Member
    • Bindu
    • Member since 04-24-2005, 10:49 AM
    • Posts 83

    Can any one explain me how to use login control to check username and password stored in sql server database. if login is succesful how can i retrive some value.

    Please provide me code also, if u can. Urgent.

    /Bindu

     

  • Re: Need help for using <asp:Login /> control

    12-29-2005, 6:14 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 1:03 AM
    • Sweden
    • Posts 5,334

    The Login control will by default use the Membership API to validate a user aginast a datasource (By default a Sql provider is used).

    If you don't want to use the Memberhip and instead use your own code (I should probably create my own Membership provider and still use the Membership feature) you can hook up to the Authenticate event of the Login control and add your own validation logic. Make sure to set the event argument's Authenticate property to true. Within the Authenticate event you can also write your code to get retrive som value from your datasource, you can also use the LoggedIn event to add some code that should be called after a user is logged in.

    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: Need help for using <asp:Login /> control

    12-29-2005, 6:15 AM
    • Contributor
      4,983 point Contributor
    • orzeh
    • Member since 07-28-2005, 11:18 AM
    • Poland
    • Posts 897
    hi!
    here is some example:

     protected void Login1_Authenticate( object sender, AuthenticateEventArgs e )
        {
            e.Authenticated = eLibraryUtils.loginUser( Login1.UserName, Login1.Password );
        }

    and the eLibraryUtils.loginUser() :

    public static bool loginUser( string user_name, string password )
        {
            bool result = false;
            SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings [ "eBConnectionString" ].ConnectionString );

            try
            {
                SqlCommand cmd = new SqlCommand( "check_user", conn );
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param = cmd.Parameters.Add( "@user_name", SqlDbType.VarChar, 20 );
                param.Value = user_name;
                param = cmd.Parameters.Add( "@pass", SqlDbType.VarChar, 20 );
                param.Value = password;
                SqlParameter user_id = cmd.Parameters.Add( "@user_id", SqlDbType.Int );
                user_id.Direction = ParameterDirection.Output;
                conn.Open();
                cmd.ExecuteNonQuery();
                if(Convert.IsDBNull( user_id.Value ))
                    return false;
                result = Convert.ToBoolean( user_id.Value );
            }
            finally
            {
                conn.Close();
            }

            return result;
        }

    hope it helps

    orzeh

    code less, think more!
  • Re: Need help for using <asp:Login /> control

    12-30-2005, 12:38 AM
    • Member
      425 point Member
    • Bindu
    • Member since 04-24-2005, 10:49 AM
    • Posts 83

     

    It is working now. Thanks all for your support.

     

Page 1 of 1 (4 items)
Microsoft Communities