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 @@ -16,6 +16,7 @@ repositories {
1616}
1717
1818dependencies {
19+ implementation(" org.springframework.security:spring-security-crypto:5.5.1" )
1920 implementation ' org.springframework.boot:spring-boot-starter-data-jpa'
2021 implementation ' org.springframework.boot:spring-boot-starter-thymeleaf'
2122 implementation ' org.springframework.boot:spring-boot-starter-validation'
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+
10+ }
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+ }
24+
25+ public String getUsername () {
26+ return username ;
27+ }
28+
29+ public boolean isMatchingPassword (String password ) {
30+ return encoder .matches (password , pwHash );
31+ }
32+
33+ }
You can’t perform that action at this time.
0 commit comments