简体   繁体   中英

Login with only username in spring security

I have a spring web application that uses spring security, I know that the normal thing is to ask users to supply their username AND PASSWORD to login but I want users to supply only their username with NO PASSWORD to login. I want to know whether spring security has a specification that does this fluently or do I have to maneuver it by specifying a password field in the html form and populate the field with password value then make the field to be a hidden field. So that the user will not see the password field, so that when he enters his username and clicks submit the system will submit both values and log him in. Any better quick fix is also welcome. my idea...

 <input type="text" name="username" required="required"/> <input type="hidden" name="password" value="passwordValue"/> 

When I was looking for, I didn't find a beautiful solution, so, I did something similar as you said. In my case, I did this:

@Bean
public PasswordEncoder passwordEncoder() {
    return NoOpPasswordEncoder.getInstance();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(service).passwordEncoder(passwordEncoder());

}

... and when I called the URL to authenticate, I pass password empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM