Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to configure machineKey in Custom Membership to use MD5 for ASP.MVC 4 (net 4.5)?
    primarykey
    data
    text
    <p>I'm implementing a CustomMembership Provider, and the first part works, login, register, etc.(I chosen the validationKey and decriptionKey for now from <a href="http://msdn.microsoft.com/en-us/library/vstudio/w8h3skw9(v=vs.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/vstudio/w8h3skw9(v=vs.100).aspx</a>).</p> <p>My Web.Config:</p> <pre><code>&lt;system.web&gt; &lt;machineKey validationKey="32E35872597989D14CC1D5D9F5B1E94238D0EE32CF10AA2D2059533DF6035F4F" decryptionKey="B179091DBB2389B996A526DE8BCD7ACFDBCAB04EF1D085481C61496F693DF5F4"/&gt; &lt;membership defaultProvider="CustomMembershipProvider"&gt; &lt;providers&gt; &lt;clear /&gt; &lt;add name="CustomMembershipProvider" type="CustomMembership.CustomMembership.CustomMembershipProvider" connectionStringName="TestMembershipEntities" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" passwordFormat="Encrypted" /&gt; &lt;/providers&gt; &lt;/membership&gt; &lt;roleManager enabled="true" defaultProvider="CustomRoleProvider"&gt; &lt;providers&gt; ... </code></pre> <p><strong>Now I need to use MD5.</strong></p> <p>The method <code>EncryptPassword</code> choose the right Algorithm, if I set validation attribute in MachineKey?</p> <pre><code>switch (PasswordFormat) { case MembershipPasswordFormat.Clear: break; case MembershipPasswordFormat.Encrypted: byte[] encryptedPass = EncryptPassword(Encoding.Unicode.GetBytes(password)); encodedPassword = Convert.ToBase64String(encryptedPass); break; case MembershipPasswordFormat.Hashed: HMACSHA1 hash = new HMACSHA1(); hash.Key = HexToByte(machineKey.ValidationKey); encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password))); break; default: throw new ProviderException("Unsupported password format."); } </code></pre> <p>Changing MachineKey</p> <pre><code>&lt;machineKey validationKey="32E35872597989D14CC1D5D9F5B1E94238D0EE32CF10AA2D2059533DF6035F4F" decryptionKey="B179091DBB2389B996A526DE8BCD7ACFDBCAB04EF1D085481C61496F693DF5F4" validation="MD5" decryption="Auto" /&gt; </code></pre> <p>If I do that, I get the follow error in <code>@Html.AntiForgeryToken()</code>:</p> <pre><code>**ConfigurationErrorsException was unhandled...** When using &lt;machineKey compatibilityMode="Framework45" /&gt; or the MachineKey.Protect and MachineKey.Unprotect APIs, the 'validation' attribute must be one of these values: SHA1, HMACSHA256, HMACSHA384, HMACSHA512, or alg:[KeyedHashAlgorithm]. </code></pre> <p>I need to write custom code to Encrypt/Decrypt MD5 in <code>case MembershipPasswordFormat.Encrypted:</code> or what I need to do, thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload