Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking to see if User Name and Password already exist.

Status
Not open for further replies.

ceyhorn

Programmer
Nov 20, 2003
93
US
I'm working on creating my user registration page and I am almost finished except that i'm stuck on how to check the sql server whether or not the user name and password are already being used, and then some logic to process this. I tried creating a custom validator function to do run a select statement for the data, needless to say that doesn't work. Any suggestions would be greatly appreciated.

Thanks in advance,
Chris
 
Chris,
You could do the simple thing and use the UserName & PW to read a dummy table. If it succeeds (you don't get an error code fro SQL) than you know that the combination has been used already. (This method may not be the most secure way though.)

Klaz
 
Klaz,
Thanks for the suggestion, but i have to have secure method of verifying that these items haven't been used before. And then allow input if they have. I have all of the code written, I just need a way to check if they exist.

Chris
 
So if you attempt to add the same user will a DB error be thrown? if so, you could catch that error and notify that the user already exists...

dlc
 
I agree with dlc.
Your userid should be unique and when inserting you should get a dup, if so catch it and tell ask user to pick another userid.

catch (SqlException sqle)
{
if (sqle.Number == 2627)//duplicate
....

Marty
 
Thanks for all of the help so far, how would I code the sql exception statement in vb?

Thanks again,
Chris
 
Can try this,

Try
'your db stuff here
Catch sqle As SqlException
If sqle.Number = 2627 Then
'you have a dup take action
End If
Catch e As Exception
'last exception routine
Finally
'clean up and close
End Try
 
Is there anyreason why you cannot do all of that in a stored proc?

Pass in username/password.

query the database to see if user exits, if it exists then return a code that you know will be exsting user, otherwise just insert it.

 
Corran007,

How would I set that up?

thanks,
Chris
 
Create Procedure checkAccount
(
@User As VarChar(50),
@PWord As VarChar(50)
)

AS

DECLARE @UserExist As Int

SELECT @UserExist = UserName
FROM tblUser
WHERE UserName = @User AND Password = @Password

IF @UserExist IsNull
BEGIN
..Your Insert
END

You Could Return A Value Here, what i do is return the ID of the inserted record if i have been succesful in adding a record, else i just return -1 and then tell the user that they already exist and that they cant use that username via my presentation layer.

Hope this helps,

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top