Here is a simple procedure to register employees of your company only to a system.
For example, l have created a site that l want only users with email ending in @kofianalytics.com to be able to register on the site. That means, once the email is validated they will have access to the site. This code is simply registering the people with the requirement they entered the valid email and password is 8 to 16 in length. There are different ways to perform this but this is just one way.

Create Procedure Register(@Email Varchar(100), @Password Varchar(100))
AS
BEGIN
SET NOCOUNT ON
DECLARE @CorrectEmail Bit = 0, @CorrectPassword Bit = 0;
IF (SELECT COUNT(*) from dbo.USER where Email= @Email) = 0
BEGIN
IF LEN(@Password) BETWEEN 8 AND 16
SET @CorrectPassword = 1
IF CHARINDEX(N’@kofianalytics.com’, @Email) <> 0
SET @CorrectEmail = 1
END

IF @CorrectPassword = 1 AND @CorrectEmail = 1
BEGIN
INSERT INTO dbo.USER(Email,Password)
VALUES(@Email,@Password)
Return 1
END
ELSE
BEGIN
Return 0
END
END

Then we can run the proceduce as below

Declare @result int
Execute @result = Register(‘vincent.amedekah@kofianalytics.com’,’password’)

After calling the procedure, you can then check if registration is successful or not and provide necessary information to the user such as check your email to confirm.
Example,

If @result = 1
print ‘Success, please confirm in your email.’

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *