TSQL to check password: Case sensitive and character check: Is this way ?

  • DECLARE @user-id INT

    DECLARE @PassWord VARCHAR(50)

    DECLARE @Ok INT

    SET @user-id = 101

    SET @PassWord = 'dgHH%Ggt4['

    SET @Ok = 0

    SET @Ok = (SELECT COUNT(*) WHERE 101 = @user-id

    AND 'dgHH%Ggt4[' = LTRIM(RTRIM(@PassWord)) COLLATE SQL_Latin1_General_Cp1_CS_AS)

    PRINT @Ok

    if PRINT = 1 it seams to sugest a correct test of a password that

    1) Character correct

    2) Case sensitive correct.

    Is the best and most TSQL accurate way to check a password for the above strict conditions.

    Any other methods ???

  • No need to invoke SELECTs.

    IF @user-id = 101 AND @Password = 'dgHH%Ggt4[' COLLATE SQL_Latin1_General_Cp1_CS_AS

    PRINT 'Ok!'

    ELSE

    PRINT 'False'

    But I doubt this is your real scenario. You do have a table where the UserID and Password is stored, right?


    N 56°04'39.16"
    E 12°55'05.25"

  • In that case, there is no need to specify the collation,

    COLLATE SQL_Latin1_General_Cp1_CS_AS

    correct me, If am wrong in my views.

    Thanks,

    Venkatesan Prabu .J

    Thanks and Regards,
    Venkatesan Prabu, 😛
    My Blog:

    http://venkattechnicalblog.blogspot.com/

  • You do have a table where the UserID and Password is stored, right?

    Yes thats is correct, all is an table. So the consensus is that my SQL is correct and the best way to achieve a password check ??

  • You do have a table where the UserID and Password is stored, right?

    Yes thats is correct, all is an table. So the consensus is that my SQL is correct and the best way to achieve a password check ??

  • You do have a table where the UserID and Password is stored, right?

    Yes thats is correct, all is an table. So the consensus is that my SQL is correct and the best way to achieve a password check ??

  • You do have a table where the UserID and Password is stored, right?

    Yes thats is correct, all is an table. So the consensus is that my SQL is correct and the best way to achieve a password check ??

  • If you ever have to "store passwords" make sure you salt and hash them.

  • this code looks goog to me:

    http://www.aspheute.com/english/20040105.asp

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply