2 Replies - 692 Views - Last Post: 09 February 2013 - 11:57 AM Rate Topic: -----

#1 Niceman99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 07-July 12

i need to retrieve username and password from SQL DB

Posted 09 February 2013 - 10:58 AM

i'm working on a school project that i need to retrieve username and password from sql database
and, depending on username and password entered, open specific windows form
i have administrator forms, managers,employees ETC.
I'm able to open the forms with this code but its not what i need cause itsnt surfing through the database
so far i havent make it work to surf the database(i guess i could but i just dont know how to open differents forms to specific username and password)
i have tried many things and needless to say none of them works
i tried with a FOR loop
as you may notice im new at programming i dont want to get it done i just want to learn
thanks for any input
private void buttonGo_Click(object sender, EventArgs e)
        {

           
            /*   //
               SqlConnection thisConnection1 = new SqlConnection(@"server=(local);Integrated security=true;" + "database=mydatabase");
               //
               SqlDataAdapter thisAdapter1 = new SqlDataAdapter("SELECT UserName,Password,Title FROM Login", thisConnection1);
               //
               SqlCommandBuilder thisbuilder1 = new SqlCommandBuilder(thisAdapter1);
               //
               DataSet thisdataset1 = new DataSet();   
               //
               thisAdapter1.Fill(thisdataset1, "Login");*/
               
                    if (TextBoxUsername.Text == "Mike" && TextBoxPassword.Text == "112")
            
                        {
                            Administration admin = new Administration();
                            admin.Visible = true;
                            admin.Activate();
                            TextBoxUsername.Clear();
                            TextBoxPassword.Clear();
                            this.Hide();
                            return;
                        }
               
                        if (TextBoxUsername.Text == "mike2" && TextBoxPassword.Text == "2012")
            
                        {
                            Admission admission = new Admission();
                            admission.Visible = true;
                            admission.Activate();
                            TextBoxUsername.Clear();
                            TextBoxPassword.Clear();
                            this.Hide();
                            return;
                        }
                            {
                            if (TextBoxUsername.Text == "mike3" && TextBoxPassword.Text == "2013")
                            { 
                                Discharge_Patients DisPa = new Discharge_Patients();
                                DisPa.Visible = true;
                                DisPa.Activate();
                                TextBoxUsername.Clear();
                                TextBoxPassword.Clear();
                                this.Hide();
                                return;
                            }
                                {
                                    if (TextBoxUsername.Text == "mike4" && TextBoxPassword.Text == "2011")
                            {
                                Patient_Report_List listPa = new Patient_Report_List();
                                listPa.Visible = true;
                                listPa.Activate();
                                TextBoxUsername.Clear();
                                TextBoxPassword.Clear();
                                this.Hide();
                                return;
                                    }
                                    {
                                        if (TextBoxUsername.Text == "mike5" && TextBoxPassword.Text == "2010")
                                        {
                                            Discharge_Patients DisPa = new Discharge_Patients();
                                            DisPa.Visible = true;
                                            DisPa.Activate();
                                            TextBoxUsername.Clear();
                                            TextBoxPassword.Clear();
                                            this.Hide();
                                            return;
                                        }
                                        }

                                    {
                                        if (TextBoxUsername.Text == "mike6" && TextBoxPassword.Text == "2009")
                                        {
                                            Discharge_Patients DisPa = new Discharge_Patients();
                                            DisPa.Visible = true;
                                            DisPa.Activate();
                                            TextBoxUsername.Clear();
                                            TextBoxPassword.Clear();
                                            this.Hide();
                                            return;
                                        }

                                    }
                                    {
                                        if (TextBoxUsername.Text == "mike6" && TextBoxPassword.Text == "2008")
                                        {
                                            Patient_Report_List DisPa = new Patient_Report_List();
                                            DisPa.Visible = true;
                                            DisPa.Activate();
                                            TextBoxUsername.Clear();
                                            TextBoxPassword.Clear();
                                            this.Hide();
                                            return;
                                        }

                                    }
                            
                            }

                }


Is This A Good Question/Topic? 0
  • +

Replies To: i need to retrieve username and password from SQL DB

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9187
  • View blog
  • Posts: 34,489
  • Joined: 12-June 08

Re: i need to retrieve username and password from SQL DB

Posted 09 February 2013 - 11:13 AM

Have you read through some the SQL tutorials?

http://www.dreaminco...basics-in-c%23/
http://www.dreaminco...a-mysql-server/
http://www.dreaminco...ery-a-database/
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5507
  • View blog
  • Posts: 11,808
  • Joined: 02-June 10

Re: i need to retrieve username and password from SQL DB

Posted 09 February 2013 - 11:57 AM

You should also stop doing this horrible use of textbox.text like it is your variable or property. Properties tutorial linked below.

Also, passwords should never be stored as anything you can actually read. They should be stored encrypted. You should not be able to decrypt them. You should instead encrypt the password the user enters and compare that encrypted result to the encrypted password stored in the DB. If the two encrypted versions match then they entered the right password. All without ever risking the security of the password.

You should NEVER be putting hardcoded usernames and passwords in your program.

You despirately need to understand better design. You should not have the kind of code repitition you have here in something so straightforward. You have this same block over and over and over.
19                            Administration admin = new Administration();
020                            admin.Visible = true;
021                            admin.Activate();
022                            TextBoxUsername.Clear();
023                            TextBoxPassword.Clear();
024                            this.Hide();
025                            return;



You seem to have missed (or just never been taught in class) a lot of foundation concepts that should have been taught long before dealing with databases.

Remember that you are not required by law to be blind to other sources of education just because you are in a class. Based on what I see here I urge you to find a secondary line of learning C# to fill in the holes of what you are learning in school; such as our C# learning series or any of the numerous 'Learn C# in 30 days' books.


My standard beginner resources post - Updated JAN 2013


Plan your study route:
There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

  • First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover.
  • Do a dozen on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.
  • Learn to plan before you type.
  • THEN you start designing software with a purpose.



I don't learn from reading books: I learn by doing.
Spoiler


Newbie/Rookie said:

I have little/no programming experience but I need to write a program by Friday that does XYZ.
Spoiler



Resources, references and suggestions for new programmers.
Spoiler

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1