ASP.NET MVC MySql Membership Provider,用户无法登录
作者:互联网
我一直在使用MySql作为asp.net mvc表单身份验证的成员资格提供程序.据我所知,我已经正确配置了东西,我可以通过注册操作和asp.net web配置站点创建用户.但是,当我尝试与其中一个用户登录时,它不起作用.它返回一个错误,好像我输入了错误的密码,或者该帐户不存在.
我已在数据库中验证该帐户确实存在.我按照这里的说明参考:http://blog.tchami.com/post/ASPNET-MVC-2-and-MySQL-Membership-Provider.aspx
这是我的web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="MySQLConn" connectionString="Server=localhost;Database=intereditor;Uid=<user>;Pwd=<password>;"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms
loginUrl="~/Account/LogOn"
timeout="2880"
name=".ASPXFORM$"
path="/"
requireSSL="false"
slidingExpiration="true"
enableCrossAppRedirects="false"
/>
</authentication>
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear/>
<add name="MySqlMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,Version=6.3.4.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true" connectionStringName="MySQLConn"
enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
passwordFormat="Hashed" maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10" passwordStrengthRegularExpression=""
applicationName="/" />
</providers>
</membership>
<profile defaultProvider="MySqlProfileProvider">
<providers>
<clear/>
<add name="MySqlProfileProvider"
type="MySql.Web.Profile.MySQLProfileProvider,MySql.Web,Version=6.3.4.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
connectionStringName="MySQLConn" applicationName="/" />
</providers>
</profile>
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
<providers>
<clear />
<add name="MySqlRoleProvider"
type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.4.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
connectionStringName="MySQLConn" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
任何人都可以帮我识别哪些错误,以便用户可以登录?
UPDATE
因此,在成员资格提供程序本身的代码中调试登录过程后,我发现提供程序中存在错误.存储在数据库中的密码哈希与基于输入的密码生成的密码之间存在差异.作为我的问题的解决方法,我将密码格式更改为’encrpyted’并将机器密钥添加到我的web.config.
我仍然有兴趣在提供程序中找出散列格式的问题,并将花费更多的时间来调试它,如果我能找出问题,我将整理一个补丁并提交它.
解决方法:
从.NET 4开始,MySQL连接器使用的散列算法从SHA1变为更复杂的(HMACSHA256).
要解决此问题,您可以更改web.config文件:
<membership
defaultProvider="AspNetMySqlMembershipProvider"
hashAlgorithmType="SHA1">
标签:mysql,asp-net-mvc-2,asp-net-membership 来源: https://codeday.me/bug/20190606/1189702.html