#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    I want to know what's wrong with this login page code !!!!


    hey ... I made a login page using C# and SQL database but actually everytime it give me " invalid login" even if I insert the correct user ....

    firstly I made this stored procedure

    ALTER Proc [dbo].[login]
    (
    @Username VarChar(50),
    @UPassword varChar(50),
    @OutRes int OUTPUT
    )
    AS
    set @OutRes = (SELECT count(*) FROM [dbo].reg_users
    WHERE Names = @Username And Pass = @UPassword)
    select case @OutRes
    when 1 then 1 --Login is Correct
    else
    0 --Bad login
    end


    then in the code

    {
    string connstring = ConfigurationManager.ConnectionStrings["website1"].ToString();



    public int Validate_Login(String Username, String Password)
    {
    SqlConnection con = new SqlConnection(connstring);
    SqlCommand selectcmd = new SqlCommand();
    selectcmd.CommandType = CommandType.StoredProcedure;
    selectcmd.CommandText = "[dbo].[login]";
    selectcmd.Parameters.Add("@Username ", SqlDbType.VarChar, 50).Value = Username;
    selectcmd.Parameters.Add("@Upassword ", SqlDbType.VarChar, 50).Value = Password;
    selectcmd.Parameters.Add("@OutRes", SqlDbType.Int, 4);
    selectcmd.Parameters["@OutRes"].Direction = ParameterDirection.Output;
    selectcmd.Connection = con;
    int results = 0;
    try
    {
    con.Open();
    selectcmd.ExecuteScalar();
    results = (int)selectcmd.Parameters["@OutRes"].Value;

    }
    catch (SqlException ex)
    {
    Label4.Text = ex.Message;

    }
    finally
    {
    selectcmd.Dispose();
    if (con != null)
    {
    con.close();
    }
    }

    return results;



    }


    and in the click button to login


    {
    int Results = 0;
    if (username_txt.Text != "" && password_txt.Text != "")
    {
    Results = Validate_Login(username_txt.Text , password_txt.Text);
    }
    else
    {
    Label4.Text
    = "Please make sure that the username and the password is Correct";
    }

    if (Results == 1)
    {
    Label4.Text =
    "Login is Good, Send the User to another page or enable controls";
    }
    else
    {
    Label4.Text = "Invalid Login";
    Label4.ForeColor = System.Drawing.Color.Red;

    }
    }





    Thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    128
    Rep Power
    0
    Wrong Response...
  4. #3
  5. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,441
    Rep Power
    4539
    This forum is for classic asp (mostly) try the NET forum for C# questions.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  6. #4
  7. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    Originally Posted by DoaaFouad
    results = (int)selectcmd.Parameters["@OutRes"].Value;
    try

    results = (int)selectcmd.Parameters.Item("@OutRes").Value;
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo