Click here to Skip to main content
16,015,641 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem when starting Windows Phone 7 Emulator [modified] Pin
nstk27-May-11 1:33
nstk27-May-11 1:33 
GeneralRe: Problem when starting Windows Phone 7 Emulator Pin
Mark Salsbery27-May-11 9:14
Mark Salsbery27-May-11 9:14 
GeneralRe: Problem when starting Windows Phone 7 Emulator Pin
nstk28-May-11 3:09
nstk28-May-11 3:09 
GeneralRe: Problem when starting Windows Phone 7 Emulator Pin
Mark Salsbery28-May-11 5:42
Mark Salsbery28-May-11 5:42 
GeneralRe: Problem when starting Windows Phone 7 Emulator Pin
nstk28-May-11 21:41
nstk28-May-11 21:41 
QuestionDataReader To DataTable Pin
Alexandra - Marie Schembri26-May-11 1:22
Alexandra - Marie Schembri26-May-11 1:22 
AnswerRe: DataReader To DataTable Pin
Blue_Boy26-May-11 1:28
Blue_Boy26-May-11 1:28 
AnswerRe: DataReader To DataTable [modified] Pin
Luc Pattyn26-May-11 1:41
sitebuilderLuc Pattyn26-May-11 1:41 
oh my. Lots of comments:

1.
please use PRE tags to improve code readability.

2.
the problem is you dispose of your reader on the first match, and then you continue the while loop which depends on the reader. The dispose should be outside the while loop!

3.
the easier way to get the dispose stuff right is by using a using statement, like so (note the result of PRE tags):
using (SqlDataReader reader = cmd.ExecuteReader()) {
    while (reader.Read()) {
        if (txtUsername.Text == (reader["UserName"].ToString()) && txtPassword.Text = reader["Password"].ToString())) {
            // whatever needs to be done on a match
            break;  // optionally shortcircuit the remainder of the loop
        }
    }
} // close the using statement, this automatically calls Dispose()


4.
So you are storing usernames and passwords in a table. Do you consider that a good practice?
Normally one would:
- [rephrased] concatenate the username, the password, and a little constant string ("salt"); [/rephrased]
- then call a hashing function;
- and lookup the table, which does not contain the password, all it holds is the hash value.
The reason is this: if your database gets compromised, all users loose the privacy of their password (and most of them would have been foolish enough to use the same username and password on other applications and/or web sites).

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Please use <PRE> tags for code snippets, they improve readability.
CP Vanity has been updated to V2.3

modified on Thursday, May 26, 2011 8:09 AM

AnswerRe: DataReader To DataTable Pin
PIEBALDconsult26-May-11 2:51
mvePIEBALDconsult26-May-11 2:51 
AnswerRe: DataReader To DataTable Pin
Dhyanga26-May-11 4:43
Dhyanga26-May-11 4:43 
GeneralRe: DataReader To DataTable Pin
Luc Pattyn26-May-11 5:31
sitebuilderLuc Pattyn26-May-11 5:31 
GeneralRe: DataReader To DataTable Pin
Dhyanga26-May-11 6:13
Dhyanga26-May-11 6:13 
AnswerRe: DataReader To DataTable Pin
Luc Pattyn26-May-11 6:24
sitebuilderLuc Pattyn26-May-11 6:24 
GeneralRe: DataReader To DataTable Pin
Alexandra - Marie Schembri26-May-11 7:40
Alexandra - Marie Schembri26-May-11 7:40 
QuestionHow to consume XML Web Services with Parameters Pin
samir.abda25-May-11 17:27
samir.abda25-May-11 17:27 
AnswerRe: How to consume XML Web Services with Parameters Pin
Mark Salsbery25-May-11 18:50
Mark Salsbery25-May-11 18:50 
GeneralRe: How to consume XML Web Services with Parameters Pin
samir.abda25-May-11 21:16
samir.abda25-May-11 21:16 
GeneralRe: How to consume XML Web Services with Parameters Pin
Mark Salsbery25-May-11 21:27
Mark Salsbery25-May-11 21:27 
GeneralRe: How to consume XML Web Services with Parameters Pin
samir.abda25-May-11 21:51
samir.abda25-May-11 21:51 
QuestionRe: How to consume XML Web Services with Parameters Pin
Mark Salsbery25-May-11 22:03
Mark Salsbery25-May-11 22:03 
AnswerRe: How to consume XML Web Services with Parameters Pin
samir.abda25-May-11 22:19
samir.abda25-May-11 22:19 
GeneralRe: How to consume XML Web Services with Parameters [modified] Pin
Mark Salsbery25-May-11 22:27
Mark Salsbery25-May-11 22:27 
GeneralRe: How to consume XML Web Services with Parameters Pin
samir.abda25-May-11 22:46
samir.abda25-May-11 22:46 
QuestionRe: How to consume XML Web Services with Parameters Pin
Mark Salsbery26-May-11 11:07
Mark Salsbery26-May-11 11:07 
QuestionRe: How to consume XML Web Services with Parameters Pin
samir.abda26-May-11 14:10
samir.abda26-May-11 14:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.