Click here to Skip to main content
15,304,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am using membership for login page,and registration ,
my registration code is working fine , but login is page is not working pls help
here is the code..
C#
MembershipUserCollection obj = System.Web.Security.Membership.FindUsersByName(txtname.Text);
           if (obj.Count == 1)
           {
               SqlParameter[] sqlParam = { new SqlParameter("UserName", SqlDbType.VarChar) };
               sqlParam[0].Value = txtname.Text;

               DataSet dsLoginDetails = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString, CommandType.StoredProcedure, "up_login", sqlParam);

               if (dsLoginDetails.Tables[0].Rows.Count.Equals(1))
               {
                   if (CalculateMD5Hash(Password.Text) == dsLoginDetails.Tables[0].Rows[0].ItemArray[0].ToString())
                   {
                       string [] roles = Roles.GetRolesForUser(txtname.Text);
                       if (roles[0] == "Admin")
                       {
                           // Add session
                           //Session["username"] = txtname.Text; I think its not converting to MD5, membership is converting to something else maybe SHA

                           Session.Add("username", txtname.Text);
                           Response.Redirect("~/adminpage.aspx",false);
                       }
                           else if (dsLoginDetails.Tables[0].Rows[0].ItemArray[1] == "teacher") ;
                           {
                               Session["username"] = txtname.Text;

                               Response.Redirect("teacher.aspx");
                           }
                       }
                       else
                       {
                           lblfail.Text = "login fail";
                       }

                   }
               }
           }
       }
   }


C#
public string MD5Hash(string text)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            //compute hash from the bytes of text
            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));

            //get hash result after compute it
            byte[] result = md5.Hash;

            StringBuilder strBuilder = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                //change it into 2 hexadecimal digits
                //for each byte
                strBuilder.Append(result[i].ToString("x2"));
            }
            return strBuilder.ToString();
        }
Posted
Updated 7-Mar-14 21:14pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900