我似乎無法找到我應該如何使用sha1通過成員資格提供商解密加密密碼。asp.net加密會員密碼和用戶名檢索
我不能在這裏使用.GetPassword()方法,因爲我從sqldatasource中檢索值並將它們放到gridview中。
這裏的GridView控件:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="UserId" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display."
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
<asp:TemplateField HeaderText="Block users">
<ItemTemplate>
<asp:Button runat="server" ID="btnBlock" CommandName="Block" CommandArgument='<%# Eval("UserId") %>'
Text="Block" OnClick="btnBlock_Click" Visible='<%# !Convert.ToBoolean(Eval("IsLockedOut")) %>' />
<asp:Button runat="server" ID="btnDeblock" CommandName="Deblock" CommandArgument='<%# Eval("UserId") %>'
Text="Deblock" OnClick="btnBlock_Click" Visible='<%# Convert.ToBoolean(Eval("IsLockedOut")) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Username">
<ItemTemplate>
<asp:Label ID="UserId" runat="server" Text='<%# Bind("UserId") %>' OnDataBinding="Decrypt" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserId" HeaderText="User id" ReadOnly="True"
SortExpression="UserId" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="LastLoginDate" HeaderText="Last login"
SortExpression="LastLoginDate" />
<asp:CheckBoxField DataField="IsLockedOut" HeaderText="Locked"
SortExpression="IsLockedOut" />
<asp:BoundField DataField="FailedPasswordAttemptCount"
HeaderText="Failed logins"
SortExpression="FailedPasswordAttemptCount" />
<asp:BoundField DataField="Comment" HeaderText="Comments"
SortExpression="Comment" />
</Columns>
</asp:GridView>
我已經更換了綁定列在一個TemplateField一個ItemTemplate。 itemtemplate中的標籤綁定到用戶名,標籤也有一個OnDataBind =「Decrypt」,它應該解密標籤的Text屬性中的值。 我一直在嘗試我在網上找到的幾個例子(甚至從這個論壇),但我對.net的理解並不是那麼棒。 下面是我在解密()偵聽器嘗試:
public void Decrypt(object sender, EventArgs e)
{
Label lbl = (Label)sender;
string decrypted = string.Empty;
UTF8Encoding encode = new UTF8Encoding();
Decoder Decode = encode.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(lbl.Text);
int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
decrypted = new String(decoded_char);
lbl.Text = decrypted;
}
我一直想把你的用戶名第一解密,我想這是密碼的方法相同。 爲了eleminate進一步的問題,這是我在web.config中
<membership defaultProvider="MembershipProvider">
<providers>
<clear/>
<add name="MembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="GustaafConnectionString"
applicationName="Gustaaf" enablePasswordRetrieval="true" enablePasswordReset="false" requiresQuestionAndAnswer="true"
requiresUniqueEmail="false" passwordFormat="Encrypted"/>
</providers>
</membership>
<machineKey validationKey="..." decryptionKey="..." validation="SHA1" decryption="AES"/>