Files
Fuchs_Intranet/db/dbo.ocms_admin_authenticate.UserDefinedFunction.sql
T

53 lines
3.3 KiB
Transact-SQL

USE [site_fuchs]
GO
/****** Object: UserDefinedFunction [dbo].[ocms_admin_authenticate] Script Date: 02.12.2020 21:05:05 ******/
DROP FUNCTION [dbo].[ocms_admin_authenticate]
GO
/****** Object: UserDefinedFunction [dbo].[ocms_admin_authenticate] Script Date: 02.12.2020 21:05:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[ocms_admin_authenticate]
(
@email varchar(255),
@password nvarchar(20)
)
RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(255) null, [email] varchar(255) NULL, [mobile] varchar(50) null)
AS
BEGIN
DECLARE @auth smallint = -1;
DECLARE @useraccount_id varchar(10), @name nvarchar(255), @mobile varchar(50);
SELECT TOP(1) @useraccount_id = [useraccount_id]
,@name = DECRYPTBYKEY(ua.[name_enc])
,@email = DECRYPTBYKEY(ua.[email_enc])
,@mobile = DECRYPTBYKEY(ua.[mobile_enc])
FROM [dbo].[ocms_useraccounts] as ua
WHERE ua.[DateDeleted] is null AND ua.[DateDisabled] is null
AND DECRYPTBYKEY(ua.[email_enc]) = @email
AND DECRYPTBYKEY(ua.[password_enc]) = @password
AND ua.[password_enc] is not null;
INSERT INTO @RET
VALUES(
@useraccount_id
,IIF(@useraccount_id is null, -1, 1)
,IIF(@useraccount_id is null, null, @name)
,IIF(@useraccount_id is null, null, @email)
,IIF(@useraccount_id is null, null, @mobile)
);
RETURN;
END
GO
ALTER AUTHORIZATION ON [dbo].[ocms_admin_authenticate] TO SCHEMA OWNER
GO