标签: two-factor-authentication

2
推荐指数
1
解决办法
3316
查看次数

ASP.NET Identity 2 无效,不存在两个因素提供程序

由于某种原因,EmailCode 未显示在有效的两因素身份验证提供程序中。然而,在我删除 PhoneCode 之前,它现在什么也没有显示。我已经调试过,它显示在 UserManager 下,但由于某些奇怪的原因 GetValidTwoFactorProvidersAsync 没有检索它。我已经尝试通过绕过该方法并手动检索值来手动添加它,但随后它会抛出 Microsoft.AspNet.Identity.EmailTokenProvider 不存在的错误消息。我无法解释为什么这不起作用。

        public async Task<ActionResult> SendCode(string returnUrl)
        {
            var userId = await SignInManager.GetVerifiedUserIdAsync();
            if (userId == null)
            {
                return View("Error");
            }
            var userFactors = await UserManager.GetValidTwoFactorProvidersAsync(userId);
            var factorOptions = userFactors.Select(purpose => new SelectListItem { Text = purpose, Value = purpose }).ToList();
            return View(new SendCodeViewModel { Providers = factorOptions, ReturnUrl = returnUrl });
        }
Run Code Online (Sandbox Code Playgroud)

身份配置

            manager.RegisterTwoFactorProvider("EmailCode", new Microsoft.AspNet.Identity.EmailTokenProvider<SystemUser>
                {
                    Subject = "SecurityCode",
                    BodyFormat = "Your security code is {0}"
                });

            manager.EmailService = new …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc two-factor-authentication asp.net-mvc-5 asp.net-identity-2

2
推荐指数
1
解决办法
3816
查看次数

ASP.NET 身份二元代码的最大过期时间是多少?

我试图找出 ASP.NET Identity 2.1 中两因素身份验证代码的最大值是多少。

我尝试过设置以下内容:

app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(60))
Run Code Online (Sandbox Code Playgroud)

但代码的有效期并不长,所以我想知道这是否是 cookie 本身的过期时间,而不是它包含的代码的过期时间。我想知道根据验证码的生成方式,验证码的持续时间是否存在技术限制。

所有示例都只是坚持 5 分钟,所以我想知道这是否是实际的限制。我在某处读到,除了 5 分钟之外还有额外的 90 秒的时间,所以这似乎是我得到的。

我注意到这个问题(ASP.Net Identity 2, Two Factor Security Code timespan)正在寻求做同样的事情,但没有一个可接受的答案,而且它已经有将近 1.5 年的历史了,所以我想我会从一个限制开始问在我费心尝试根据该答案更改它之前,请先了解一下我的观点。

asp.net two-factor-authentication asp.net-identity

2
推荐指数
1
解决办法
4597
查看次数

安全生成 6 个 MFA 引脚

我正在尝试生成用于 2 因素身份验证的 6 位代码,乍一看我可能会这样做:

Random random = new Random();
var securitycode = random.Next(1000000, 10000000);
Run Code Online (Sandbox Code Playgroud)

然而,这对我来说似乎有些不安全,因为如果您可以通过获取大量安全代码来找出种子,则可能有一种方法可以预测下一个数字。

我认为有更好的方法来获取安全代码,RNGCryptoServiceProvider但我对如何确保生成的代码是 6 位数字有点困惑

private string GenerateSecurityCode(int length)
{
    var provider = new RNGCryptoServiceProvider();
    var byteArray = new byte[8];
    provider.GetBytes(byteArray);
    var code = BitConverter.ToUInt32(byteArray, 0);
    //how can I assure the code is 6 digits
}
Run Code Online (Sandbox Code Playgroud)

这是生成 MFA 代码的安全方法吗?如果不是,生成数字代码的好方法是什么?

c# security two-factor-authentication multi-factor-authentication

1
推荐指数
1
解决办法
1781
查看次数

Spring Boot 与 Spring Security - 使用 SMS/PIN/TOTP 的两因素身份验证

我正在开发一个 Spring Boot 2.5.0 Web 应用程序,并使用 Thymeleaf 进行 Spring Security 表单登录。我正在寻找有关如何使用 Spring Security 表单登录实现两因素身份验证(2FA)的想法。

要求是当用户使用他的用户名和密码登录时。在登录表单中,如果用户名和密码验证成功,则应将短信代码发送到用户注册的手机号码,并应在另一个页面上要求用户输入短信代码。如果用户正确获取短信代码,他应该被转发到安全的应用程序页面。

在登录表单上,除了用户名和密码外,还要求用户输入验证码图像中的文本,该文本使用SimpleAuthenticationFilter扩展的验证UsernamePasswordAuthenticationFilter

这是当前的SecurityConfiguration

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Autowired
    private CustomUserDetailsServiceImpl userDetailsService;
    
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
            .addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class)    
            .authorizeRequests()
                .antMatchers(
                        "/favicon.ico",
                        "/webjars/**",
                        "/images/**",
                        "/css/**",
                        "/js/**",
                        "/login/**",
                        "/captcha/**",
                        "/public/**",
                        "/user/**").permitAll()
                .anyRequest().authenticated()
            .and().formLogin()
                .loginPage("/login")
                    .permitAll()
                .defaultSuccessUrl("/", true)
            .and().logout()
                .invalidateHttpSession(true)
                .clearAuthentication(true)
                .deleteCookies("JSESSONID")
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                .logoutSuccessUrl("/login?logout")
                    .permitAll()
            .and().headers().frameOptions().sameOrigin()
            .and().sessionManagement()
                .maximumSessions(5)
                .sessionRegistry(sessionRegistry())
                .expiredUrl("/login?error=5");
    }

    public SimpleAuthenticationFilter authenticationFilter() throws …
Run Code Online (Sandbox Code Playgroud)

spring-security two-factor-authentication thymeleaf spring-boot

0
推荐指数
1
解决办法
1万
查看次数