SIGN UP MEMBER LOGIN:    
Blog

Easy Login using ASP.NET

Posted by Mohammad Mirshahi Blogs | ASP.NET Controls in C# Nov 29, 2011
Here is sample code that uses a database for easy login.
Download Files: EasyLogin.zip
This sample is an ASP.NET Easy login control.

Before runing program you should attach current database in App_Data to your SQL Server. 

Here is the try file stream for using manual cookie.


Notic !

        if (File.Exists(pah) == true)
        {
            string str1, str2;
            string connection = @"Data Source=mirshahi;Initial Catalog=addressbook;Integrated Security=True";

            con = new SqlConnection(connection);
            cmd.CommandText = "select * from Login";
            cmd.Connection = con;
            con.Open();
            dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (dr.Read())
            {
                str1 = dr.GetString(1);
                str2 = dr.GetString(2);

                ////////////////////////


                StreamReader sr = new StreamReader(pah);

                string us = sr.ReadLine();
                string ps = sr.ReadLine();
                if (str1.Equals(us) == true && str2.Equals(ps) == true)
                {
                    l1.Text = "Wellcome !You Are Login...";
                    Login1.UserName = us;

                    Login1.FindControl("LoginButton").Visible = false;
                    sr.Close();
                }
                else if (str1.Equals(us) == false && str2.Equals(ps) == false)
                {

                    l1.Text = "You Are Log Out,Please Connect...!";

                }
            }
            con.Close();
        }
        else
        {
            //l1.Text = "You Are Log Out !";
            Login1.FindControl("LoginButton").Visible = true;


            string str1, str2, stu, stp;
            string connection = @"Data Source=mirshahi;Initial Catalog=addressbook;Integrated Security=True";

            con = new SqlConnection(connection);
            cmd.CommandText = "select * from Login";
            cmd.Connection = con;
            con.Open();
            dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            try
            {
                while (dr.Read())
                {
                    str1 = dr.GetString(1);
                    str2 = dr.GetString(2);

                    ////////////////////////
                    stu = Login1.UserName;
                    stp = Login1.Password;
                    stu.Trim(); stp.Trim(); str1.Trim(); str2.Trim();
                    if (stu.Equals(str1) == true && stp.Equals(str2) == true)
                    {

                        Login1.FailureText = l1.Text;
                       
                        StreamWriter sw = File.CreateText(pah);
                        sw.WriteLine(str1);
                        sw.WriteLine(str2);
                        sw.Close();
                        con.Close();
                       
                       
                        Response.Redirect("enter.aspx");
                        check1();
                        if (stu.Equals(str1) == false && stp.Equals(str2) == false)

                            Login1.FailureText = l1.Text;
                        check1();
                    }

                } check1();
            }
            catch (Exception)
            {
            }


Checking my manual cookie of file stream when loged in.
ENJOY IT...



DOWNLOAF FILE ANOTHE WEB :

http://mfc-project.blogfa.com/post-20.aspx

OR :

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7409&lngWId=10
share this blog :
post comment