Skip to content

Commit 7e4dd55

Browse files
Maria UsinaMaria Usina
authored andcommitted
User model
1 parent f2400c2 commit 7e4dd55

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
@@ -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

2829
tasks.named('test') {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)