File tree Expand file tree Collapse file tree
src/main/java/org/launchcode/codingevents Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ dependencies {
2323 implementation ' mysql:mysql-connector-java:8.0.32'
2424 developmentOnly ' org.springframework.boot:spring-boot-devtools'
2525 testImplementation ' org.springframework.boot:spring-boot-starter-test'
26+ implementation(" org.springframework.security:spring-security-crypto:5.5.1" )
2627}
2728
2829tasks. named(' test' ) {
Original file line number Diff line number Diff line change 1+ package org .launchcode .codingevents .data ;
2+
3+ import org .launchcode .codingevents .models .User ;
4+ import org .springframework .data .repository .CrudRepository ;
5+
6+ public interface UserRepository extends CrudRepository <User , Integer > {
7+
8+ User findByUsername (String username );
9+ }
Original file line number Diff line number Diff line change 1+ package org .launchcode .codingevents .models ;
2+
3+ import jakarta .persistence .Entity ;
4+ import jakarta .validation .constraints .NotNull ;
5+ import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
6+
7+ @ Entity
8+ public class User extends AbstractEntity {
9+
10+ @ NotNull
11+ private String username ;
12+
13+ @ NotNull
14+ private String pwHash ;
15+
16+ private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder ();
17+
18+ public User () {}
19+
20+ public User (String username , String password ) {
21+ this .username = username ;
22+ //this.pwHash = password;
23+ this .pwHash = encoder .encode (password );
24+ }
25+
26+ public String getUsername () {
27+ return username ;
28+ }
29+
30+ public boolean isMatchingPassword (String password ) {
31+ return encoder .matches (password , pwHash );
32+ }
33+
34+ }
You can’t perform that action at this time.
0 commit comments