Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8073329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:18:32+00:00 2026-06-05T14:18:32+00:00

I am using Spring 3 and grabbing users from a MySQL database. Right now,

  • 0

I am using Spring 3 and grabbing users from a MySQL database.

Right now, in testing, I have a user with a MD5 password. And I can authenticate just fine using that.

However, we want to be a little more secure in how we hash the passwords. We want to:

MD5(username + salt + password)

The salt is a random string stored in the user record. But I can’t seem to figure out where/how to do this. This is what I have so far:

UserDao

public class UserDao {

    public static Users findUserByUsername(String paUsername) {
        String hql = "from Users where username = :username";

        List<Users> list = null;
        Users user = null;

        try {
            IO io = new IO("web");   // custom Hibernate framework
            IOQuery query = new IOQuery();
            query.setStatement(hql);
            query.setParameter(new IOParameter("username", paUsername));

            list = io.runQuery(query);

            if (list.isEmpty()) {
                return null;
            }

            return list.get(0);

        } catch (Exception ex) {
            return null;
        }
    }
}

UserDetailsServiceImpl

@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String paUsername) throws UsernameNotFoundException {
        Users user = userDao.findUserByUsername(paUsername);

        if(user == null) {
            throw new UsernameNotFoundException("User not found");
        }

        return new User(
                user.getUsername(),
                user.getPassword(),
                user.getEnabled(),
                true,
                true,
                true,
                getAuthorities(Enums.UserRoles.IT));
    }

    private Collection<? extends GrantedAuthority> getAuthorities(Enums.UserRoles paRole) {
        List<GrantedAuthority> authList = getGrantedAuthorities(getRoles(paRole));
        return authList;
    }

    private List<String> getRoles(Enums.UserRoles paRole) {
        List<String> roles = new ArrayList<>();

        if (paRole.equals(Enums.UserRoles.USER)) {
            roles.add(Enums.UserRoles.USER.name());
        } else if (paRole.equals(Enums.UserRoles.IT)) {
            roles.add(Enums.UserRoles.USER.name());
            roles.add(Enums.UserRoles.IT.name());
        }

        return roles;
    }

    private static List<GrantedAuthority> getGrantedAuthorities(List<String> paRoles) {
        List<GrantedAuthority> authorities = new ArrayList<>();
        for (String role : paRoles) {
            authorities.add(new SimpleGrantedAuthority(role));
        }
        return authorities;
    }
}

UserDetailsService

public class UserDetailService implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return new UserDetailsServiceImpl().loadUserByUsername(username);        
    }
}

security-app-context

<beans:bean id="loginSuccessHandler" class="com.myapp.security.LoginSuccessHandler" />
<beans:bean id="loginFailureHandler" class="com.myapp.security.LoginFailureHandler" />
<beans:bean id="detailsService" class="com.myapp.security.UserDetailService" />

Any ideas on what I need to do?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:18:33+00:00Added an answer on June 5, 2026 at 2:18 pm

    This is a fragment of the security config my app uses to set password encoding:

    <sec:authentication-manager alias="authenticationManager">
        <sec:authentication-provider ref="authenticationProvider" />
    </sec:authentication-manager>
    
    
    <bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
        <property name="userDetailsService" ref="userDetailsServiceImpl"/>
        <property name="passwordEncoder" ref="cryptoPasswordEncoder" />
    </bean>
    
    
    <bean id="cryptoPasswordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
    

    We don’t need to set a Salt source in the DaoAuthenticationProvider because the BCryptPasswordEncoder uses its own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using spring mvc in my application,when i created user i have to
Using Spring 2.5 tag library, I have an Integer value in a command form
I have an iPhone app which submits user entered data to a SQL database.
Using Spring Security 3 along with Struts 2 and Tiles 2, I have a
I have got my strtok working, but now because I am using scanf which
When using spring security, specifically with @notation; what is the proper way to access
I am using spring/hibernate stand alone application. if i dont configure Transactions i am
Hi I am using spring jdbctemplate to invoke an oracle function which takes an
i am using spring 3.1.0.RELEASE , and my servlet container is tomcat 7 and
I am using Spring MVC 3.1.x with Tiles 2.2.2 (bootstrapped project with Roo) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.