is there a way to take user login from SQL database
hello,
I am designing a web site using ASP.Net over VB , and I need to have user login window, I 've had it from the control and the users specified from the ASP.net configuration but : I wonder if I can bind users from a table containing usernames and passwords in my SQL database connected to my site?
please urgent help is needed
even a website I can have benefit
knowledgelover
Junior Poster in Training
86 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
Yeah the way that you explained it is very difficult to understand. What do you mean binding the table from the database to your site? Just do a simple search and compare passwords. If it is successful, the user can login. Do this with the scalar method then compare the passwords with
string.compare(password, retrievedpassword, False)
If it returns zero, then you have a match, otherwise -1 or 1 will be a failure. Do something like this:
if (String.Compare(strPassword, strScalarRetrievedInfo, False)) = 0 then
'do your success login here
else
'failed login code here
end if
Keep this in mind, if.. end if statements are faster than Select Case statements. However, if.. elseif.. end if statements are SLOWER than Select Case statements.
So if you are only looking for one value like the above code, use if.. end if. If you are looking for different ones, avoid elseif and use select case methods because it is drastically faster when using many of them.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
thank u very much
I appreciate your help and I am using it now :)
knowledgelover
Junior Poster in Training
86 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
Keep this in mind, if.. end if statements are faster than Select Case statements. However, if.. elseif.. end if statements are SLOWER than Select Case statements.
So if you are only looking for one value like the above code, use if.. end if. If you are looking for different ones, avoid elseif and use select case methods because it is drastically faster when using many of them.
It's faster? Really? Has someone benchmarked this? I'd be willing to bet that the compiler takes a Select Case and turns it into an if-elseif-else chain.
That said, if you're using a database, then you just need to run a select statement like Fungus said and see if you get a result. That way you don't need a case for every user on your site.
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
http://www.blackwasp.co.uk/SpeedTestIfElseSwitch.aspx
Oh, you got told.
The reason why the Select statement is faster is listed in the article. Yes it compiles the same, but a select case can be reordered any way the compiler wishes, while the if.. else statement cannot. This means that it has to go through every if else to find the right one, where it can pull the only case that is correct. Take a look, the time is considerably faster!
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
and the problem with searching a user the way Fungus has explained is that the user's password is not case sensitive. Do a test. Make the user's pass UserCaseSenseTest and try to get a result with: usercasesensetest
You will get a result, even though the cases are different.
By executing a scalar and retrieving the pass (if there is a user, else this will not execute), you can then compare the strings with case-sensitivity.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
As this has turned out to be an interesting learning experience, I may as well point out that the MSIL for the switch and the if-elseif are different. Apparently, switch is directly supported in MSIL.
That said, such a minor optimization is silly to worry about. :P
And for a login system, a database query really is the best easiest way to do it, especially if you already have a DB in place.
*exeunts gracefully*
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
Yeah, although it is faster, it is really minimal on a moderate level. The only time you would see a difference is when you are doing more loops then you would ever do in real life. I mean, out of 1 billion loops, you would see a 5 second time improvement.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
thaaaaaaaaaaanks a lot :)
knowledgelover
Junior Poster in Training
86 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0