Welcome to Dream.In.Code
Become an Expert!

Join 150,072 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,791 people online right now. Registration is fast and FREE... Join Now!




Login using mysql

 
Reply to this topicStart new topic

Login using mysql

blue1
20 Feb, 2008 - 05:24 PM
Post #1

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 5

hi i would like to know how to establish a connection to my sql using the membership login page.
csharp
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
MySqlConnection conDatabase = new MySqlConnection("Server=localhost;Persist Security Info=no;User ID=Administrator");
MySqlConnection cnnVideos = new MySqlConnection("Network Address=localhost;" +
"Initial Catalog='login';" +
"Persist Security Info=no;" +
"User Name='root';" +
"Password=''");

}

User is offlineProfile CardPM
+Quote Post

Footsie
RE: Login Using Mysql
21 Feb, 2008 - 10:52 PM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
What errors are you getting?
Does it or doesn’t it connect when using your code?
Did you create the membership login page yourself?

Give us a few more details and maybe we can help you out. I’ve had a bit of experience with MySql myself and may be able to point you in the right direction.
wink2.gif

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Login Using Mysql
21 Feb, 2008 - 11:22 PM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Use code.gif tags when posting code.
User is offlineProfile CardPM
+Quote Post

blue1
RE: Login Using Mysql
21 Feb, 2008 - 11:36 PM
Post #4

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 5

I have improved my code to this
csharp

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{


MysqlConnection conn = new MysqlConnection(ConnectionString);
conn.Open();
MysqlCommand cmd =conn.CreateCommand();
cmd.CommandText = "SELECT * FROM login.accounts a";
cmd.CommandType =CommandType.Text;
MysqlDataReader rdr = cmd.ExecuteReader();
}

The following it what i expect the program to run but i am stuck.
1. the user login from the login page
2. the program will run through the mysql database.
3. If the username and password are matched, the user is able to login

This post has been edited by jayman9: 22 Feb, 2008 - 12:30 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Login Using Mysql
22 Feb, 2008 - 12:29 AM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
POST YOUR CODE IN BETWEEN TAGS, LIKE THIS code.gif

How many times do you I have to say it.

Thank you.
User is offlineProfile CardPM
+Quote Post

Footsie
RE: Login Using Mysql
22 Feb, 2008 - 10:52 AM
Post #6

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
To see how to access your MySql database read through this topic: Click here PsychoCoder lays it out very nicely here and it should get you going.

Your SELECT statement won't work here.
'SELECT *' will return everything in that table.

What you need to do is compare the username entered to the username in your database, and the password entered to the password in your database and if they match they are allowed access.

CODE
"SELECT COUNT(*) FROM login WHERE (Username=?username) AND (Password=?password)";
This does a count where the variables entered match the database entry and return a count (you're looking for 1 which is a match or 0 which fails) The ?password is the password that is entered. I had a similar question which the guys here at DIC helped to resolve: Click here Read through this thread.

Also when you open your connection, always make sure you close it again, as quickly as possible, and wrap it in a try, catch, finally block.
csharp
 
try
{
//open and execute command
conn.Open();
cmd.ExecuteScalar;
}
catch(Exception ex)
{
// catch any errors here
}
finally
{
//always do this
conn.Close();
}


Hope this helps. smile.gif

User is offlineProfile CardPM
+Quote Post

blue1
RE: Login Using Mysql
26 Feb, 2008 - 01:46 AM
Post #7

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 5

thanks it does help me . I would like to know if anyone know how to display the username using session id . This is to enable the user to go to a certain page
User is offlineProfile CardPM
+Quote Post

dippy1
RE: Login Using Mysql
3 Mar, 2008 - 07:09 AM
Post #8

D.I.C Head
**

Joined: 29 Nov, 2005
Posts: 68


My Contributions
I have been using this code to display the current user by using a session cookie

CODE
<%
    if request.cookies("logincheck") <> "" then
        response.Write("<p><b><font size='5'>Current User: " & request.Cookies("logincheck")("Firstname") & "&nbsp;" &  request.Cookies("logincheck")("Surname") & "</h2></b></font></p>")
        if request.cookies("logincheck")("UserType") = "Member" then
%>


User is offlineProfile CardPM
+Quote Post

zai
RE: Login Using Mysql
6 Mar, 2008 - 07:52 PM
Post #9

New D.I.C Head
*

Joined: 17 Feb, 2008
Posts: 16


My Contributions
hi, i have a very simple question. rite now i'm trying to do login in asp.net and i'm new in this. i've read all the msg on top. but i don't understand a few thing. i'm using microsoft visual to do my project using asp.net. so why is it different when i see the coding here? why is it there's a symbol {, /.
User is offlineProfile CardPM
+Quote Post

Footsie
RE: Login Using Mysql
8 Mar, 2008 - 03:03 AM
Post #10

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
The code with the curly braces "{}" that you see above is from the code-behind page in ASP.net. (Right click in the designer and select view code)

The language is C#. There are a variety of languages available in Microsoft Visual Studio (Visual Basic is another one - which doesn't have the {}).
"{" denotes the start of a block of code and "}" denotes the end. They are used to group statements together.

The "//" means that what follows is a comment/note for the programmer and is ignored by the compiler.

Is this what you were looking for?

This post has been edited by Footsie: 8 Mar, 2008 - 03:04 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:03PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month