login and regsitration using stored proedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peerraghu
    New Member
    • Nov 2007
    • 30

    login and regsitration using stored proedure

    Hi i want to create login and registration button in web page, by creating a stored procedure in sql server, just help me how to create those procedure and how can i give parameters to the login button

    thank you
    raghu
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by peerraghu
    Hi i want to create login and registration button in web page, by creating a stored procedure in sql server, just help me how to create those procedure and how can i give parameters to the login button

    thank you
    raghu
    a simple stored procedure will look like..........

    Code:
     
    CREATE PROCEDURE sp_UserValidation
    (
    @Username varchar(50),
    @UserPassword varchar(10)
    ) 
    AS
    IF EXISTS (SELECT UserName FROM tblLogIn WHERE UserName=@Username and UserPassword=@UserPassword)
    BEGIN
    return 1
    END
    ELSE
    BEGIN
    return 0
    END
    GO
    call a function like the following to validate the user...pass the Username and Password to the function....... ..........code is in C#......

    [CODE=css]
    public int UserValidation( string uname,string pass)
    {
    int retVal=0;
    cmdTrans = new SqlCommand();
    cmdTrans.Connec tion = myConnection;
    cmdTrans.Comman dType = CommandType.Sto redProcedure;
    cmdTrans.Comman dText="sp_UserV alidation";
    SqlParameter param1=new SqlParameter("@ Username",SqlDb Type.VarChar,50 );
    param1.Value=un ame;
    SqlParameter param2=new SqlParameter("@ UserPassword",S qlDbType.VarCha r,10);
    param2.Value=pa ss;
    SqlParameter param3=new SqlParameter("@ Return",SqlDbTy pe.Int,4);
    param3.Directio n=ParameterDire ction.ReturnVal ue;
    cmdTrans.Parame ters.Add(param1 );
    cmdTrans.Parame ters.Add(param2 );
    cmdTrans.Parame ters.Add(param3 );
    cmdTrans.Execut eNonQuery();
    retVal = (int) param3.Value;
    if (!(myConnection == null))
    {
    myConnection.Cl ose();
    }
    return retVal;
    }[/CODE]
    if the user is valid then the function UserValidation( ) will return 1

    hope it will help you.......

    Comment

    • peerraghu
      New Member
      • Nov 2007
      • 30

      #3
      thank a lot ,I made through you code

      Comment

      • peerraghu
        New Member
        • Nov 2007
        • 30

        #4
        hi dip
        i created the login information in my website but if want to update the profile of paticular login member what r the process just send me sample codding

        thank you in advance

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          A better stored procedure will look like..........

          Code:
           
          CREATE PROCEDURE usp_UserValidation
          (
          @Username varchar(50),
          @UserPassword varchar(10)
          ) 
          AS
          set nocount on
          IF EXISTS (SELECT UserName FROM tblLogIn WHERE UserName=@Username and UserPassword=@UserPassword)
          BEGIN
          return 1
          END
          ELSE
          BEGIN
          return 0
          END
          GO
          The value 1 or 0 is returned and I do not see how it is used. Also a try/catch block would be better in case of errors.

          Suggest peerraghu you start writing your own code if you want to learn.

          Comment

          Working...