Taras Danylchenko
Taras Danylchenko

Reputation: 347

How to decode password in SHA-1 (with salt) with AuthenticationManagerBuilder

Have a class which registers users

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDAO userDAO;

    @Autowired
    private RoleDAO roleDAO;

    @Autowired
    private ShaPasswordEncoder shaPasswordEncoder;

    @Override
    public void save(User user) {

        user.setPassword(shaPasswordEncoder.encodePassword(user.getPassword(),"mySalt"));
        System.out.println(user.getPassword());
        Set<Role> roles = new HashSet<>();
        roles.add(roleDAO.getOne(1L));
        user.setRoles(roles);
        userDAO.save(user);

    }

    @Override
    public User findByUsername(String username) {
        return userDAO.findByUsername(username);
    }

As you see I encode in Sha with salt. Here I'm trying to encode

    @Bean
    public ShaPasswordEncoder getShaPasswordEncoder(){

        return new ShaPasswordEncoder();
    }
    @Autowired
    public void registerGlobalAuthentication(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .userDetailsService(userDetailsService)
                .passwordEncoder(getShaPasswordEncoder());
    }

So where can I specify a salt to decode the password?

Upvotes: 0

Views: 1962

Answers (1)

dunni
dunni

Reputation: 44545

You can't decode a hashed password. A hash function is a one way function. Thus there is no way of specifying a salt to decode.

Upvotes: 1

Related Questions