2012-11-09 120 views
0

所以,我正在構建一個需要訪問最初爲asp.net創建的數據庫的站點。我想使用與已經在數據庫中使用的asp.net站點相同的用戶名和密碼。開發人員提到,在asp.net中使用了默認身份驗證。從數據庫在Coldfusion中的asp.net sql身份驗證

舉例密碼:sYWPXNvJlVNs8EVZvIQOSaWfQ4I =

例PasswordSalt從數據庫中:ruNTdhelY57ghQsTFz/TIG ==

這是我曾嘗試:

<cfquery name="auth" datasource="ct"> 
SELECT userid, Password, PasswordSalt from dbo.aspnet_Membership 
WHERE userid = '#auth1.userid#' 
</cfquery> 

<cfset cfHash = toBase64(hash(auth.PasswordSalt & cookie.password, "SHA1"))> 

<cfif cfHash eq auth.Password> ...then authenticate etc. 

我已經嘗試了很少有迭代,但沒有去,所產生的cfHash結果太長了,像這樣:

OUJBOUJENjI0MzEzNjM3M0EwQjk3Nzc3ODIzNUVGMkJCOD czOEI0Qg ==

任何想法?

+0

像這樣的事情想出了大約3個月前標記的ColdFusion 。檢查ASP安全設置以查看使用哪個方案。我認爲有一個加密和散列實現。 – barnyr

+0

我撒謊,它沒有標籤coldfusion,但它是在我的活動飼料:http://stackoverflow.com/questions/2547397/how-to-create-a-asp-net-membership-provider-hashed -password-manually/2551717#2551717 – barnyr

+0

是的,我已經看到了代碼,並試圖在Coldfusion中複製,無濟於事... – Phil

回答

1

(編輯:原來的答覆並不適用於所有情況大幅修改...)

This thread可能是你所追求的。總之,兩個關鍵區別是:


<cfscript> 
    thePassword = "password12345"; 
    base64Salt = "l+g9MUcs+cLExeDTNy8M+A=="; 
    // extract bytes of the salt and password 
    saltBytes = binaryDecode(base64Salt, "base64"); 
    passBytes = charsetDecode(thePassword, "UTF-16LE"); 

    // next combine the bytes. note, the returned arrays are immutable, 
    // so we cannot use the standard CF tricks to merge them  
    ArrayUtils = createObject("java", "org.apache.commons.lang.ArrayUtils"); 
    dataBytes = ArrayUtils.addAll(saltBytes, passBytes); 

    // hash binary using java 
    MessageDigest = createObject("java", "java.security.MessageDigest").getInstance("SHA-1"); 
    MessageDigest.update(dataBytes);  
    theBase64Hash = binaryEncode(MessageDigest.digest(), "base64"); 

    WriteOutput("theBase64Hash= "& theBase64Hash &"<br/>"); 
</cfscript>