2011-11-15 49 views
0

我有一个称为登录用户名和密码都使用ENCRYPTBYPASSPHRASE检查是否在SQL数据库中存在加密的用户名

然而,当我插入一个新的登录帐户,我想请检查是否新登录的用户名没有按加密表”已经存在。

如何检查数据库中是否存在用户名?

我试过像select * from login where username = encryptbypassphrase('username', 'passphrase')这样的东西,但是出现了负面情况。

+0

我认为你必须交换的用户名和密码:'从登录选择*其中username = encryptbypassphrase(“密码”,“用户名”)'见:http://technet.microsoft.com/en-us/library/ms190357.aspx –

+0

你是对的,谢谢。但在这个示例/问题中,这并不重要,因为我使用相同的加密来插入并检查用户是否存在。 –

+0

在哪个字段中存储加密霉素的结果? –

回答

0

我希望像这些使用:

--- For INSERT 
insert into login 
    (username, encryptedphrase) 
values 
    ('username', encryptbypassphrase('username', 'passphrase')) 

--- Checking a specific username, passphrase combination: 
select * 
from login 
where username = 'username' 
    and encryptedphrase = 
     encryptbypassphrase(username, 'passphrase') 

--- Checking if a specific username already exists: 
select exists 
     (select * 
     from login 
     where username = 'username' 
     ) userexists 
+0

用户名已加密。所以说“username ='username'”不起作用。 –

+0

所以,你实际上只存储'encryptbypassphrase('username','passphrase')'? –

相关问题