Click here to Skip to main content
14,088,376 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i have two tables namely student and users. In student table i am having fields Id, Name, Password. In users table i am having id, name, password etc.

Now my question is select two tables with password column only in stored procedure. In this line i want to use OR for selecting two tables. Why i require is if the user changes the password then it has to check whether the user is in the student table or user table. For this i am setting a value to local variable with that variable accessing the tables and updating the password.

This password fields varchar(max) datatype

What I have tried:

SET @@CurrentPassword4db = ((SELECT [Password] FROM Users WHERE UserId = @guidUserId) OR (SELECT [Password] FROM Student WHERE StudentId = @guidStudentId))


Can anyone tell me the correct way to achieve this goal. Thanks in advance
Here
@@CurrentPassword4db is varchar(max)
datatype
Posted
Updated 29-Sep-18 21:41pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Several things wrong here:
1) Never store passwords in clear text - it is a massive security problem. Passwords should be hashed, and the hash value stored in the DB. This requires changes to your presentation software, and there is an example here for C#: Password Storage: How to do it.[^]

2) Why have two tables storing the same thing? That just risks potential duplication and problems. Instead, have one table with a column that says if the row is for a User or a Student. That way all your login, registration, change password, etc. code becomes a whole load cleaner as it is all stored in the same place. With your scheme, it's quite possible to get the same userID in two different tables and then you never know what is going on!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190518.1 | Last Updated 30 Sep 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100