Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get Number of Row which contains text

Author  Topic 

doctorzeus
Starting Member

2 Posts

Posted - 2013-07-21 : 08:18:58
Hello,

The title pretty much explains what I am trying to achieve, basically I have to columns; One contains "Username" and the other contains "Password".

I am trying to create a query that checks the username column for a specific value and then if it is found returns the row number so it can be checked against the password..

I am fairly new to SQL so if there is a better way of doing this please feel free to make suggestions (keeping in mind the database is being queried from a asp.net web service)..

Many Thanks

DoctorZeus

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-07-21 : 09:37:56
You are doing the completely wrong. The password should be hashed with SHA1/2 (at least with MD5) and perhaps even salted.
Then you query the table if BOTH the password and the hashed password match. If they do, then you act upon that.
If there is no match, then you act upon that.

Never ever store passwords in clear text in a database.


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-07-21 : 09:39:04
I am not sure why you want to get row number, but here is a way to get the password given the user name:
[CODE]

-- TEST DATA
DECLARE @MyTable TABLE (UserName VARCHAR(10), [Password] VARCHAR(10));
INSERT INTO @MyTable VALUES
('John', 'Giotto'),
('James', 'Aryabhata'),
('George', 'Sagan'),
('Mary', 'Picard'),
('Rama', 'Kepler'),
('Victor', 'Tatyana');

-- RETURN PASSWORD
SELECT [Password] from @MyTable where UserName = 'James';


[/CODE]

Go to Top of Page
   

- Advertisement -