Quote:
Originally Posted by kembl
One more bad things exists with this code
Change binary 16 string in value @pwd
Code:
SELECT @pwd = 0xC3371572F8F9BF71A8D31A1EB2436D6
to some else which nobody knows, cause if some one finds password forthis value, he gets access to any one account on your server after 5 mistakes. It's better to random generate there some unique every time, but in this way procedure will be more slowly.
|
Hi
I'm not good in SQL , but this , in my mind , fixed problem with static @PWD...
Decrypt password is easy , if I use , for example only small letter , it take about 3 minutes at my computer... This is more security, if randomise generate password every time.
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[ap_GPwd] @account varchar(14), @pwd binary(16) output
AS
--exec ap_GPwd_log @account
-- Created By darkangel
-- 20xx.xx.19
-- updated 20xx.xx.14 by KEMBL
-- set Account's auth logging
-- updated 20xx.xx.31 Logrus, Drone
-- added login counts per time check
-- update 20xx.xx.25 by Stpavel
-- added random generate password
DECLARE @RandPass varchar(32)
DECLARE @counter smallint
DECLARE @RandNum float
DECLARE @RandNumInt tinyint
DECLARE @CurrChar varchar(1)
DECLARE @ValidChar varchar(255)
SET @ValidChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+&$'
DECLARE @ValidCharLength int
SET @ValidCharLength = len(@ValidChar)
SET @CurrChar = ''
SET @RandNum = 0
SET @RandNumInt = 0
SET @RandPass = ''
SET NOCOUNT ON
if (SELECT COUNT(*) FROM lin2db..user_auth_log WHERE account=@account AND DATEDIFF(mi, dt, GETDATE()) < 16) > 4
OR
(SELECT COUNT(*) FROM lin2db..user_auth_log WHERE account=@account AND DATEDIFF(ss, dt, GETDATE()) < 3) > 0
BEGIN
INSERT INTO user_auth_log (account,success) VALUES (@account, 0)
SET @counter = 1;
WHILE @counter < (17)
BEGIN
SET @RandNum = Rand();
SET @RandNumInt = Convert(tinyint, ((@ValidCharLength - 1) * @RandNum + 1))
SELECT @CurrChar = SUBSTRING(@ValidChar, @RandNumInt, 1);
SET @counter = @counter + 1;
SET @RandPass = @RandPass + @CurrChar;
END
SET NOCOUNT OFF
SELECT @pwd=convert(binary(16),@RandPass);
END
ELSE
BEGIN
INSERT INTO user_auth_log (account,success) VALUES (@account, 1)
SET NOCOUNT OFF
SELECT @pwd=password FROM user_auth with (nolock) WHERE account=@account
END