locked
how to check validate account before approve new account RRS feed

  • Question

  • User-1399352090 posted

    Hi,

    how can i check user account isvalid or not befor approve. i have use below code but user account always false.

    Code:

    MembershipUser user = Membership.GetUser(userId);//user id will get from query string
    if (Membership.ValidateUser(txtUserName.Text.Trim(), txtPassword.Text.Trim()))// here i'm getting always false
        {
         user.IsApproved = true;
         Membership.UpdateUser(user);
         lblMessage.Text = "Congrats! your account has been approved";
         }
    else
        {
       lblMessage.Text = "invalied Details";
        }

    Appreciate for Best and Quick response.

    Tuesday, September 27, 2016 12:56 PM

All replies

  • User-225949985 posted

    how can i check user account isvalid or not befor approve.

    Isn't that what you're doing by setting IsApproved to true only if the user is valid?

    i have use below code but user account always false.

    I think you have a different issue. If you're always getting false when calling Membership.ValidateUser, it's because you're using the wrong username or password. Make sure you're entering the right data, perhaps by looking directly into the database to confirm.

    Tuesday, September 27, 2016 4:46 PM
  • User-1399352090 posted

    I think you have a different issue. If you're always getting false when calling Membership.ValidateUser, it's because you're using the wrong username or password. Make sure you're entering the right data, perhaps by looking directly into the database to confirm.

    i'm using proper user details, is it showing false because user account wasn't approved.

    but my point is how can i check as valid user before i set IsApproved to true

    Wednesday, September 28, 2016 6:50 AM
  • User283571144 posted

    Hi smd_yasin,

    As far as I know, "validateuser" method will always return false if the user account wasn't approved.

    From MSDN:

    The IsApproved value for a membership user is checked during the call to ValidateUser by the SqlMembershipProvider. If the IsApproved property is set to false, the ValidateUser method returns false even if the supplied user name and password are correct.

    So I suggest you could update the isapproved value firstly, then use validateuser method to check the user's password.

    If "validateuser" method return false, set user account "isapproved" value to false again.

    More details, you could refer to follow codes:

    MembershipUser user = Membership.GetUser(userId);//user id will get from query string
    user.IsApproved = true;
    Membership.UpdateUser(user);
    if (Membership.ValidateUser(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
    {
    lblMessage.Text = "Congrats! your account has been approved";
    }
    else
    {
    user.IsApproved = false;
    Membership.UpdateUser(user);
    lblMessage.Text = "invalied Details";
    }

    Besides, if you want to know how to check as valid user before you set IsApproved to true, I suggest you could create a custom membership user class and add the custom validateuser methods to the custom MembershipUser class.

    More details, you could refer to follow link:

    https://forums.asp.net/t/1111310.aspx?Membership+ValidateUser+where+isapproved+false

    Best Regards,

    Brando

    Thursday, October 6, 2016 2:13 AM