Skip to content

Commit 2745138

Browse files
committed
user-model branch complete
1 parent f8af4aa commit 2745138

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ repositories {
1616
}
1717

1818
dependencies {
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'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)