3 database questions
-
Hi, I have a SQL database with usernames and passwords. 1)Now I need find a user name (which user wrote into textbox) and prove the password. 2)I have a registration page, it works well, but I would like to search the database before I add the new record to it, (no duplicity) 3)How can I delete a record? (update record) Thanks very much for your answer
-
Hi, I have a SQL database with usernames and passwords. 1)Now I need find a user name (which user wrote into textbox) and prove the password. 2)I have a registration page, it works well, but I would like to search the database before I add the new record to it, (no duplicity) 3)How can I delete a record? (update record) Thanks very much for your answer
None of these questions can be answered without knowing the schema of your database, you should be able to answer them all from the books online, and this smells like homework :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Hi, I have a SQL database with usernames and passwords. 1)Now I need find a user name (which user wrote into textbox) and prove the password. 2)I have a registration page, it works well, but I would like to search the database before I add the new record to it, (no duplicity) 3)How can I delete a record? (update record) Thanks very much for your answer
1. For security you should always store the passwords in an encrypted form. When the user registers for the first type encrypt the password. When the user logs in on subsequent sessions encrypt the password again and search for the encrypted version of the password.
SELECT COUNT(*) FROM myRegistrationTable WHERE UserName=@userName AND EncryptedPassword=@encryptedPassword
The above code will return 0 if the user name and password cannot be found, or 1 otherwise. If it returns any other value the database contains duplicate information. 2. You can apply a unique constraint to the table to ensure that no duplicates are entered. Also the primary key is by default a unique value - so sufficient uniqueness may already be covered. If you do this SQL Server will raise an error when you perform your insert and you can pick this up in your .NET application by catching the SqlException that is generated. You could also write a stored procedure that checks for the existance of a record first then conditionally inserts the new record if there isn't one already. 3. Use the
DELETE
command. Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!