{"id":1936,"date":"2019-07-14T12:00:00","date_gmt":"2019-07-14T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/spring-security-tutorial-storing-user-credential-in-mysql-database\/"},"modified":"2026-07-05T03:24:03","modified_gmt":"2026-07-05T01:24:03","slug":"spring-security-tutorial-storing-user-credential-in-mysql-database","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/spring-security-tutorial-storing-user-credential-in-mysql-database\/","title":{"rendered":"Spring Security Tutorial 2 \u2013 Storing User Credential in MySQL Database"},"content":{"rendered":"<p>This tutorial follows from the<a href=\"https:\/\/kindsonthegenius.com\/tempsite\/introduction-to-spring-security-a-practical-tutorial\/\"> Part 1<\/a>.<\/p>\n<p>Here, we would see how to use mySQL database. We are going to store username and password in the database.<\/p>\n<ul>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/introduction-to-spring-security-a-practical-tutorial\/\">Tutorial 1 &#8211; Introduction to Spring Security\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/spring-security-tutorial-storing-user-credential-in-mysql-database\/\">Tutorial 2 &#8211; Storing Login Details in MySQL<\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/spring-security-tutorial-3-encoding-your-password\/\">Tutorial 3 &#8211; Using BCrypt Password Encoder<\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/spring-security-tutorial-4-create-your-own-login-form\/\">Tutorial 4 &#8211; Custom Login Form<\/a><\/li>\n<\/ul>\n<p>These are the steps:<\/p>\n<ol>\n<li><a href=\"#t1\">Configure mySQL database<\/a><\/li>\n<li><a href=\"#t2\">Ensure the necessary dependencies are available<\/a><\/li>\n<li><a href=\"#t3\">Create the User entity<\/a><\/li>\n<li><a href=\"#t4\">Configure AuthenticationProvider<\/a>\n<ul>\n<li>Create a bean of AuthenticationProvider type<\/li>\n<li>It returns a DaoAuthenticationProvider<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#t5\">Create the UserDetailsService<\/a><\/li>\n<li><a href=\"#t6\">Create the UserRepository<\/a><\/li>\n<li><a href=\"#t7\">Create a Class the implements the UserDetails Interface<\/a><\/li>\n<li><a href=\"#t8\">Final AppSecurity Config<\/a><\/li>\n<li><a href=\"#t9\">Test the Application<\/a><\/li>\n<li><a href=\"#t10\">Next Steps<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h5 id=\"t1\"><strong>1. Configure mySQL database<\/strong><\/h5>\n<p>To configure the database, you need to add the necessary mySQL connection properties in the application.properties file.<\/p>\n<p>All the properties, you need to add are given as:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">spring<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">datasource<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">driver<\/span><span style=\"color: #333333;\">-<\/span>class<span style=\"color: #333333;\">-<\/span>name<span style=\"color: #333333;\">=<\/span>com<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">mysql<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">cj<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jdbc<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">Driver<\/span>\nspring<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">datasource<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">password<\/span><span style=\"color: #333333;\">=<\/span>root\nspring<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">datasource<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">username<\/span><span style=\"color: #333333;\">=<\/span>root\nspring<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">datasource<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">url<\/span><span style=\"color: #333333;\">=<\/span><span style=\"color: #997700; font-weight: bold;\">jdbc:mysql:<\/span><span style=\"color: #888888;\">\/\/localhost:3307\/usersdb<\/span>\nspring<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jpa<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">hibernate<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">ddl<\/span><span style=\"color: #333333;\">-<\/span>auto<span style=\"color: #333333;\">=<\/span>update\n<\/pre>\n<p><span style=\"color: #800000;\"><em>You may have to include ?serverTimezone=UTC to the url<\/em><\/span><\/p>\n<p>Notice that the name of the database is usersdb and the port number is 3307.<\/p>\n<p>Now, this databases should exist. (you should create it in mySQL and so you must have mySQL running in your system)<\/p>\n<p>Also, you need to create a table with three fields:<\/p>\n<ul>\n<li>id<\/li>\n<li>username<\/li>\n<li>password<\/li>\n<\/ul>\n<p>Add a test record into the database. For me I added two records:<\/p>\n<ul>\n<li>id: 1;\u00a0 \u00a0username: Hercules;\u00a0 \u00a0password: gift<\/li>\n<li>id: 2;\u00a0 \u00a0username: Archilles;\u00a0 \u00a0password: gold<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h5 id=\"t2\"><strong>2. Ensure the necessary dependencies are available<\/strong><\/h5>\n<p>The two dependencies you need to add to your pom.xml includes:<\/p>\n<ul>\n<li>spring-boot-starter-jpa<\/li>\n<li>spring-boot-starter-security<\/li>\n<li>mysql-connector-java<\/li>\n<\/ul>\n<p>You can get these dependencies in <a href=\"https:\/\/mvnrepository.com\/\" target=\"_blank\" rel=\"noopener\">Maven Repository.<\/a> You can also copy them from below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;dependency&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;groupId&gt;<\/span>mysql<span style=\"color: #007700;\">&lt;\/groupId&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;artifactId&gt;<\/span>mysql-connector-java<span style=\"color: #007700;\">&lt;\/artifactId&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;version&gt;<\/span>8.0.15<span style=\"color: #007700;\">&lt;\/version&gt;<\/span>\n<span style=\"color: #007700;\">&lt;\/dependency&gt;<\/span>\n\n<span style=\"color: #007700;\">&lt;dependency&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;groupId&gt;<\/span>org.springframework.boot<span style=\"color: #007700;\">&lt;\/groupId&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;artifactId&gt;<\/span>spring-boot-starter-data-jpa<span style=\"color: #007700;\">&lt;\/artifactId&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;version&gt;<\/span>2.1.4.RELEASE<span style=\"color: #007700;\">&lt;\/version&gt;<\/span>\n<span style=\"color: #007700;\">&lt;\/dependency&gt;<\/span>\n\n<span style=\"color: #007700;\">&lt;dependency&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;groupId&gt;<\/span>org.springframework.boot<span style=\"color: #007700;\">&lt;\/groupId&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;artifactId&gt;<\/span>spring-boot-starter-security<span style=\"color: #007700;\">&lt;\/artifactId&gt;<\/span>\n    <span style=\"color: #007700;\">&lt;version&gt;<\/span>2.1.6.RELEASE<span style=\"color: #007700;\">&lt;\/version&gt;<\/span>\n<span style=\"color: #007700;\">&lt;\/dependency&gt;<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<h5 id=\"t3\"><strong>3. Create the User entity<\/strong><\/h5>\n<p>You will also need to create a class that represents the User table in the database. This class should be the same name with the table created in MySQL.<\/p>\n<p>Follow the steps below:<\/p>\n<p><strong>Step 1:<\/strong> Create the User class<\/p>\n<p><strong>Step 2:<\/strong> Annotate this class with the <em><strong>@Entity<\/strong> <\/em>annotation<\/p>\n<p><strong>Step 3:<\/strong> Annotate the Id with the<strong><em> @Id<\/em><\/strong> annotation.<\/p>\n<p><strong>Step 4:<\/strong> Generate the Constructors as well as the getters and setters.<\/p>\n<p>At the end, the the User class will be as shown below.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Entity<\/span>\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">User<\/span> <span style=\"color: #333333;\">{<\/span>\n\t\n\t<span style=\"color: #555555; font-weight: bold;\">@Id<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> Integer Id<span style=\"color: #333333;\">;<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> String username<span style=\"color: #333333;\">;<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> String password<span style=\"color: #333333;\">;<\/span>\n\t\n\t<span style=\"color: #888888;\">\/\/Constructor<\/span>\n\t<span style=\"color: #888888;\">\/\/Getters and Setters<\/span>\n\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h5 id=\"t5\"><strong>4. Create the User Repository<\/strong><\/h5>\n<p>Anytime you need to access data from a database, you would need to create a repository.<\/p>\n<p>Follow the steps below to add a repository:<\/p>\n<p><strong>Step 1:\u00a0<\/strong> In the repositories package, create an interface, <strong>UserRepository<\/strong>.<\/p>\n<p><strong>Step 2:<\/strong> Annotate this class with the @Repository annotation<\/p>\n<p><strong>Step 3:<\/strong> Make this class extend jpaRepository.<\/p>\n<p><strong>Step 4:<\/strong> Specify the entity type and the primary key type<\/p>\n<p><strong>Step 5:<\/strong>\u00a0Add\u00a0a method definition for\u00a0<strong>findByUsername. <\/strong>Ittakes a String parameter of username and returns a user object.<\/p>\n<p>The content of the UserRepository is as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Repository<\/span>\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">interface<\/span> <span style=\"color: #bb0066; font-weight: bold;\">UserRepository<\/span> <span style=\"color: #008800; font-weight: bold;\">extends<\/span> JpaRepository<span style=\"color: #333333;\">&lt;<\/span>User<span style=\"color: #333333;\">,<\/span> Long<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #333333;\">{<\/span>\n\t\n\tUser <span style=\"color: #0066bb; font-weight: bold;\">findByUsername<\/span><span style=\"color: #333333;\">(<\/span>String username<span style=\"color: #333333;\">);<\/span>\n\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h5 id=\"t4\"><strong>5. Configure AuthenticationProvider<\/strong><\/h5>\n<p>We would still use the <em><strong>AppSecurityConfig<\/strong> <\/em>file we created in the previous lesson. But this time, we would configure the provider.\u00a0We need to create a method that returns type <strong><em>AuthentictionProvider<\/em><\/strong>. Inside this method;<\/p>\n<p><strong>Follow the steps below:<\/strong><\/p>\n<p><strong>Step 1:<\/strong> Delete everything from the AppSecurityConfig class ( you can also comment them out if that&#8217;s what you prefer)<\/p>\n<p><strong>Step 2:<\/strong>\u00a0Autowire UserDetailsService into this class (UserDetailsService is not yet created)<\/p>\n<p><strong>Step 3:<\/strong> Create a public method that returns AuthenticationProvider object. I name it <em>authProvider<\/em><\/p>\n<p><strong>Step 4:\u00a0<\/strong>Annotate this method with the @Bean annotation so it becomes a spring bean.<\/p>\n<p><strong>Step 5:<\/strong> Create a new <em><strong>DaoAuthenticationProvider<\/strong><\/em> object. I name it <em>provider<\/em>.<\/p>\n<p><strong>Step 6:<\/strong> S<span style=\"font-size: 1rem;\">et the UserDetailsService\u00a0 of this provider to the autowired UserDetailsService using setUserDetailsService<\/span><\/p>\n<p><strong>Step 7:<\/strong> Set the PasswordEncoder of the provider to NoOpPasswordEncoder.getInstance using setPasswordEncoder.<\/p>\n<p><strong>Step 8:<\/strong> Then return the DaoAuthenticationProvider object, provider.<\/p>\n<p>At this point, the AppSecurityConfig class would be as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Configuration<\/span>\n<span style=\"color: #555555; font-weight: bold;\">@EnableWebSecurity<\/span>\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">AppSecurityConfig<\/span> <span style=\"color: #008800; font-weight: bold;\">extends<\/span> WebSecurityConfigurerAdapter <span style=\"color: #333333;\">{<\/span>\n\t\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> UserDetailsService userDetailsService<span style=\"color: #333333;\">;<\/span>\n\t\n\t<span style=\"color: #555555; font-weight: bold;\">@Bean<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> AuthenticationProvider <span style=\"color: #0066bb; font-weight: bold;\">authProvider<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\n\t\t\n\t\tDaoAuthenticationProvider provider <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> DaoAuthenticationProvider<span style=\"color: #333333;\">();<\/span>\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> provider<span style=\"color: #333333;\">;<\/span>\n\t<span style=\"color: #333333;\">}<\/span>\t\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<h5 id=\"t5\"><strong>6. Create the Service Layer (UserDetailsService)<\/strong><\/h5>\n<p>Now we need to create a <em><strong>UserDetailsService<\/strong>\u00a0interface. The UserDetailsService <\/em>is used for retrieving user-related data from the repository. It contains on method called loadUserByUsername(). You can override this method to customize how a user is retrieved. In this example, we will retrieve a user and wrap it into a UserPrincipal object. This is what we&#8217;ll do.<\/p>\n<p>Follow the steps below:<\/p>\n<p><strong>Step 1:<\/strong> Create a cIass, I named it <strong><em>MyUserDetailsService. <\/em><\/strong>In the New Class dialog box, add the UserDetails interface. This class provides a method called loadUserByUsername. It takes a String parameter of username.<\/p>\n<p><strong>Step 2:<\/strong> Annotate the class with the @Service annotation.<\/p>\n<p><strong>Step 3:<\/strong> Autowire the <em><strong>UserRepository<\/strong> <\/em>into the <em><strong>UserDetailsService<\/strong><\/em><\/p>\n<p><strong>Step 4:\u00a0<\/strong> Inside the loadUserByUsername method, create a User object. This object calls the repository findByUsername method, passing it the username parameter.<\/p>\n<p><strong>Step 5:<\/strong> Validate that if the user is null, then throw new UsernameNotFoundException<\/p>\n<p><strong>Step 6:<\/strong> Return new UserPrincipal object passing it the user you created in step 4.<\/p>\n<p>At the end, the content of the service would be:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">MyUserDetailsService<\/span> <span style=\"color: #008800; font-weight: bold;\">implements<\/span> UserDetailsService <span style=\"color: #333333;\">{<\/span>\n\t\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> UserRepository userRepository<span style=\"color: #333333;\">;<\/span>\n\n\t<span style=\"color: #555555; font-weight: bold;\">@Override<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> UserDetails <span style=\"color: #0066bb; font-weight: bold;\">loadUserByUsername<\/span><span style=\"color: #333333;\">(<\/span>String username<span style=\"color: #333333;\">)<\/span> <span style=\"color: #008800; font-weight: bold;\">throws<\/span> UsernameNotFoundException <span style=\"color: #333333;\">{<\/span>\n\t\t\n\t\tUser user <span style=\"color: #333333;\">=<\/span> userRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findByUsername<\/span><span style=\"color: #333333;\">(<\/span>username<span style=\"color: #333333;\">);<\/span>\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>user<span style=\"color: #333333;\">==<\/span><span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">throw<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">UsernameNotFoundException<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"User not found!\"<\/span><span style=\"color: #333333;\">);<\/span>\n\t\t<span style=\"color: #333333;\">}<\/span>\n\t\t<span style=\"color: #888888;\">\/\/so what do we return? So we would create a class that implements UserDetails<\/span>\n\t\t\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">UserPrincipal<\/span><span style=\"color: #333333;\">(<\/span>user<span style=\"color: #333333;\">);<\/span>\n\n\t<span style=\"color: #333333;\">}<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h5 id=\"t7\"><strong>7. Create a class the Implements UserDetails interface<\/strong><\/h5>\n<p>We\u00a0 will now create a class that implements the UseDetails interface. The UserDetails interface provides core user information as well as methods for managing users. Follow the steps below:<\/p>\n<p><strong>Step 1:<\/strong> Create a new class inside the models package . This class should implement the <strong>UserDetails<\/strong> interface. Choose the interface from the New Class dialog box. I call this class <strong><em>UserPrincipal<\/em><\/strong>. This is because Principal means the current user.<\/p>\n<p><strong>Step 2:<\/strong> Set the methods in this class to return true by default<\/p>\n<p><strong>Step 3:<\/strong> Add one more private field of type User to this class<\/p>\n<p><strong>Step 4:<\/strong> Generate a constructor that takes a User object as parameter<\/p>\n<p><strong>Step 5:<\/strong> Then modify the <strong><em>getPassword()<\/em><\/strong> and <em><strong>getUsername()<\/strong><\/em> methods to return<em><strong> user.getPassword()<\/strong><\/em>\u00a0and <em><strong>user.getUsername()<\/strong><\/em> respectively.<\/p>\n<p><strong>Step 6:<\/strong> Also, modify the <em><strong>getAuthorities()<\/strong> <\/em>method to return Authorities collection. This you can do using the line below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">return<\/span>  Collections<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">singleton<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">new<\/span> SimpleGrantedAuthority<span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"USER\"<\/span><span style=\"color: #333333;\">));<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<h5 id=\"t8\"><strong>8. Final AppSecurityConfig File<\/strong><\/h5>\n<p>For your final AppSecurityConfig, check that:<\/p>\n<ul>\n<li>the <strong>UserDetailsService<\/strong> of the provider is set<\/li>\n<li>the <strong>PasswordEncoder<\/strong>\u00a0is set as well<\/li>\n<li>that there is no error!<\/li>\n<\/ul>\n<p>The final content of the <strong>AppSecurityConfig<\/strong> file would be as follows:<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Configuration<\/span>\n<span style=\"color: #555555; font-weight: bold;\">@EnableWebSecurity<\/span>\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">AppSecurityConfig<\/span> <span style=\"color: #008800; font-weight: bold;\">extends<\/span> WebSecurityConfigurerAdapter <span style=\"color: #333333;\">{<\/span>\n\t\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> UserDetailsService userDetailsService<span style=\"color: #333333;\">;<\/span>\n\t\n\t<span style=\"color: #555555; font-weight: bold;\">@Bean<\/span>\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> AuthenticationProvider <span style=\"color: #0066bb; font-weight: bold;\">authProvider<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\n\t\t\n\t\tDaoAuthenticationProvider provider <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> DaoAuthenticationProvider<span style=\"color: #333333;\">();<\/span>\n\t\t\n\t\tprovider<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">setUserDetailsService<\/span><span style=\"color: #333333;\">(<\/span>userDetailsService<span style=\"color: #333333;\">);<\/span>\n\t\t\n\t\tprovider<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">setPasswordEncoder<\/span><span style=\"color: #333333;\">(<\/span>NoOpPasswordEncoder<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getInstance<\/span><span style=\"color: #333333;\">());<\/span>\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> provider<span style=\"color: #333333;\">;<\/span>\n\t<span style=\"color: #333333;\">}<\/span>\t\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<h5 id=\"t9\"><strong>9. Test the Application<\/strong><\/h5>\n<p>At this point, you have completed the configuration. Congrats!<\/p>\n<p>Launch the application. Visit the home page http:\/\/localhost:8080\/home.<\/p>\n<p>Try to login with the test user you added to the mySQL database. If you are able, to log in, great!. If not, watch the<a href=\"https:\/\/www.youtube.com\/watch?v=vZ-BAFMe4Bo\" target=\"_blank\" rel=\"noopener\"> video lesson<\/a> to learn why<\/p>\n<p>&nbsp;<\/p>\n<h5 id=\"t10\"><strong>10. Next Steps<\/strong><\/h5>\n<p>Now we have been able to authenticate using data stored in a database. But some things are yet to be done. For instance, how do we create user details? Or maybe how do we customize the login form or use our own login form.<\/p>\n<p>There may be other challenges you may have as well. We would discuss these in the next lesson.<\/p>\n<p>Feel free to watch the video lessons and also subscribe to my channel so you don&#8217;t miss an update.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/Nc5k1zn50Y8\" width=\"100%\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\ufeff<\/span><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial follows from the Part 1. Here, we would see how to use mySQL database. We are going to store username and password in &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[311],"tags":[],"class_list":["post-1936","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1936"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1936\/revisions"}],"predecessor-version":[{"id":2104,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1936\/revisions\/2104"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}