converting console base application to windows form
-
can u have any xample which is readymade. Now i have understand that my code is something wrong.. Can you provide me an xample where i can understand the whole scenario. A form which is used for login
qureshiaquib wrote:
Can you provide me an xample where i can understand the whole scenario
Nope. I am a college professor and it would be against my principles to just hand over a full-blown example, you would not learn much from it. 1. Design your form with your appropriate labels and text boxes (extra credit if you make the password text box **** out the password as it is typed in ), and a log in button. 2. Recycle/reuse your database connection code in which you can run the query after clicking the log in button. 3. If things don't work out well the first time, experiment around with it and use some creativity. You can do it :-D Also, you do not want to store passwords for the user in plain text inside the database. You might want to study up on cryptographic hash functions as well. I am leaving this for you to research and enrich your learning with.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
-
hey members i need some help. i have made this console base app which connects to a database and retrieves the data from two column. same it is like a login check form. but can i convert this into a windows form application which consist of two text boxes and a login button need some help thanks in advance using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; namespace c_database { class program { static void main(string[] aqu) { string connectionstring =@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\aquib\my documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf;Integrated Security=True;User Instance=True"; SqlConnection connection= new SqlConnection(connectionstring); try { connection.Open(); Console.WriteLine("connection open"); Console.WriteLine(""); } catch (Exception e) { Console.WriteLine(e); Console.Read(); } Console.Write("username>"); string username =Console.ReadLine(); Console.Write("Password>"); string password =Console.Read(); SqlCommand command = new SqlCommand("SELECT * FROM [USERS] WHERE Username='" + username + "' AND Password ='" + password + "'" , connection); SqlDataReader reader = null; reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine("welcome" + reader["username"].ToString()); Console.Read(); } Console.WriteLine("user" +username + "does Not exist" ); goto } } }
As mentioned -- definitely never concatenate your SQL statements -- use parameters. Here's a link to another excellent article here that bears on your situation: Password Storage: How to do it.[^] I'll also mention that you should use a layered approach: User Interface Layer -- You have the console app, you can write a WinForms app that uses the same layers beneath here. Business Logic Layer -- encapsulates the logic of validating the login details (and other things) (SQL goes here). Data Access Layer -- encapsulates the details of connecting to and interacting with the database. Try it, learn it, live it -- you'll be way ahead of your classmates, and you'll become a chick magnet :cool: .
-
with what exactly means? i just want to build a form which checks the user id and a password from the database which is already present. a simple login windows form which redirect to another form if the password is correct or if the password is not correct then redirects to the same login form. a simple of two text boxes and a submit button. but the code..what to do with that? mine is of console based. how to do it in windows form i am a student.learning programming in university can u help me out
qureshiaquib wrote:
i am a student.learning programming in university
..as I'm reading it, you are doing the learning "here". Welcome to CodeProject University I guess :badger: When is the assignment due? Any chance we could sneak in a short piece (using the
CPVanity
class) to deny users with a negative reputation access for the first two tries?Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
As mentioned -- definitely never concatenate your SQL statements -- use parameters. Here's a link to another excellent article here that bears on your situation: Password Storage: How to do it.[^] I'll also mention that you should use a layered approach: User Interface Layer -- You have the console app, you can write a WinForms app that uses the same layers beneath here. Business Logic Layer -- encapsulates the logic of validating the login details (and other things) (SQL goes here). Data Access Layer -- encapsulates the details of connecting to and interacting with the database. Try it, learn it, live it -- you'll be way ahead of your classmates, and you'll become a chick magnet :cool: .
Excellent suggestion on the layers. Griff's article I second as well.
PIEBALDconsult wrote:
be way ahead of your classmates, and you'll become a chick magnet
:laugh: That is signature material right there :-D
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
-
hey members i need some help. i have made this console base app which connects to a database and retrieves the data from two column. same it is like a login check form. but can i convert this into a windows form application which consist of two text boxes and a login button need some help thanks in advance using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; namespace c_database { class program { static void main(string[] aqu) { string connectionstring =@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\aquib\my documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf;Integrated Security=True;User Instance=True"; SqlConnection connection= new SqlConnection(connectionstring); try { connection.Open(); Console.WriteLine("connection open"); Console.WriteLine(""); } catch (Exception e) { Console.WriteLine(e); Console.Read(); } Console.Write("username>"); string username =Console.ReadLine(); Console.Write("Password>"); string password =Console.Read(); SqlCommand command = new SqlCommand("SELECT * FROM [USERS] WHERE Username='" + username + "' AND Password ='" + password + "'" , connection); SqlDataReader reader = null; reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine("welcome" + reader["username"].ToString()); Console.Read(); } Console.WriteLine("user" +username + "does Not exist" ); goto } } }
First do Right-Click on Project > References and add the Windows.Forms.dll to the project. then you need to add the namespaces to your class. After that right click on Project and select Properties; From "Application" tab set output type to "Windows Application". Good Luck
Meysam
-
qureshiaquib wrote:
i am a student.learning programming in university
..as I'm reading it, you are doing the learning "here". Welcome to CodeProject University I guess :badger: When is the assignment due? Any chance we could sneak in a short piece (using the
CPVanity
class) to deny users with a negative reputation access for the first two tries?Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
due is within this week. :| i donno how to do that.
-
qureshiaquib wrote:
Can you provide me an xample where i can understand the whole scenario
Nope. I am a college professor and it would be against my principles to just hand over a full-blown example, you would not learn much from it. 1. Design your form with your appropriate labels and text boxes (extra credit if you make the password text box **** out the password as it is typed in ), and a log in button. 2. Recycle/reuse your database connection code in which you can run the query after clicking the log in button. 3. If things don't work out well the first time, experiment around with it and use some creativity. You can do it :-D Also, you do not want to store passwords for the user in plain text inside the database. You might want to study up on cryptographic hash functions as well. I am leaving this for you to research and enrich your learning with.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
i can also learn from the project. i can read that and understand. i hae to submit my project but bymistakenly i have mae a console app. plz sir provide me with a readmade form i will understand that whole project. but i cant copy because i have to explain the whole scenario like a presentation so dont bother that i am simply copying and getting my assingment done
-
due is within this week. :| i donno how to do that.
Read Meysams post, has given you a description of what needs to be done. ..and you should be able to do this within a week, it's not much code. Panicking won't help either, it's more a matter of sitting down, reading the post and Googling a lot :)
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
Read Meysams post, has given you a description of what needs to be done. ..and you should be able to do this within a week, it's not much code. Panicking won't help either, it's more a matter of sitting down, reading the post and Googling a lot :)
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
what is meysam post?
-
what is meysam post?
qureshiaquib wrote:
what is meysam post?
Not a what, but a "whom". I was referring to a good answer to your question that has been sent to you by someone with that name[^]. Did you succeed in adding a reference to the project yet?
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]