Home > database >  Pull the email related to the username entered in a textBox
Pull the email related to the username entered in a textBox

Time:03-30

This is a Visual Basic Windows Form App

I'm working on a forget password form, my idea is that the user enters their userID on a textBox and an email is sent to them with a one-time password.

I already have everything designed, but I don't know how to pull the email from SQL taking in consideration that the user will be entering only their userID on a textBox.

All the login and register functions are created and working. I have a sql table "users" with "userID, password and email".

CodePudding user response:

You have to add new column that will contain recovery password. This column must be updated every time you send "I forgot my password" request.

Examples:

-- your table alredy exists
CREATE TABLE users ([userID] INT PRIMARY KEY IDENTITY(1, 1), [password] VARCHAR(100), email varchar(100));
-- Add new column to users table. This column will contain recovery password
ALTER TABLE users ADD recovery_password VARCHAR(100) NULL;

INSERT INTO users (password, email) VALUES ('Password #1', '[email protected]');

-- you have to use TextBox component with a Text property instead of "1" value
-- you have to create some algorythm to create encrypted password for recovery_password column
UPDATE users SET recovery_password = 'SECRET CODE' WHERE [UserID] = 1

And the last query that you looking for looks so:

-- Use this query to compare typed password by user and the recovery password 
SELECT recovery_password FROM users WHERE [UserID] = 1

The same examples: db<>fiddle

  • Related