CREATE TABLE Users ( UserID Varchar(10), UserPW Varchar (20))INSERT INTO USERS values('TestUser1',ENCRYPT('TestPW1')) INSERT INTO USERS values('TestUser2',ENCRYPT('TestPW2')) INSERT INTO USERS values('TestUser3',ENCRYPT('TestPW3')) INSERT INTO USERS values('TestUser4',ENCRYPT('TestPW4'))SELECT * from Users where UserID = 'TestUser2' and UserPW = ENCRYPT('TestPW2')--不区分大小写 INSERT INTO USERS values('TestUser1',ENCRYPT(UPPER('TestPW1')))
你可以在输入数据之后采用xor方式加密,进入的数据就是一些其他数据,出来后就再用xor解密
--SQL SERVER 本身也提代加密密码的函数: --pwdencrypt ,pwdcompare --加密: declare @logintable table(username varchar(20),passwd varbinary(256)) insert @logintable(username,passwd) values('yourname',pwdencrypt('123456'))declare @pwd varbinary(256)select @pwd=passwd from @logintable where username='yourname' --比较: if pwdcompare('12356',@pwd)=1 print 'true' else print 'false'select * from @logintabledeclare @tt0 int,@tt1 int,@tt2 int,@tt3 varchar(30),@ttkey int declare @role tinyint declare @new char(30)select @new=要加密数据select @ttkey=convert(int,(@tt2/@tt0)) select @tt3='' select @tt0=len(@new)select @tt1=1 while @tt1<=@tt0 begin select @tt2=ascii(substring(@new,@tt1,1))^(@ttkey+@tt1) --if char(@tt2)="'" -- select @tt3=@tt3+'$' --else begin select @tt3=@tt3+char(@tt2) end select @tt1=@tt1+1 endselect @tt3 -加密结果
UserID Varchar(10),
UserPW Varchar (20))INSERT INTO USERS values('TestUser1',ENCRYPT('TestPW1'))
INSERT INTO USERS values('TestUser2',ENCRYPT('TestPW2'))
INSERT INTO USERS values('TestUser3',ENCRYPT('TestPW3'))
INSERT INTO USERS values('TestUser4',ENCRYPT('TestPW4'))SELECT * from Users where UserID = 'TestUser2'
and UserPW = ENCRYPT('TestPW2')--不区分大小写
INSERT INTO USERS values('TestUser1',ENCRYPT(UPPER('TestPW1')))
--pwdencrypt ,pwdcompare
--加密:
declare @logintable table(username varchar(20),passwd varbinary(256))
insert @logintable(username,passwd) values('yourname',pwdencrypt('123456'))declare @pwd varbinary(256)select @pwd=passwd from @logintable where username='yourname'
--比较:
if pwdcompare('12356',@pwd)=1
print 'true'
else
print 'false'select * from @logintabledeclare @tt0 int,@tt1 int,@tt2 int,@tt3 varchar(30),@ttkey int
declare @role tinyint
declare @new char(30)select @new=要加密数据select @ttkey=convert(int,(@tt2/@tt0))
select @tt3=''
select @tt0=len(@new)select @tt1=1
while @tt1<=@tt0
begin
select @tt2=ascii(substring(@new,@tt1,1))^(@ttkey+@tt1)
--if char(@tt2)="'"
-- select @tt3=@tt3+'$'
--else
begin
select @tt3=@tt3+char(@tt2) end
select @tt1=@tt1+1
endselect @tt3 -加密结果