Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package mate.academy.exception

// Provide your code here for PasswordValidationException class
class PasswordValidationException(message: String) : Exception(message)
8 changes: 7 additions & 1 deletion src/main/kotlin/mate/academy/service/PasswordValidator.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package mate.academy.service

import mate.academy.exception.PasswordValidationException

const val MIN_PASSWORD_LENGTH = 10

// This class will validate password requirements
class PasswordValidator {
fun validate(password: String, repeatPassword: String) {
// write your code here
if (password != repeatPassword || password.length < MIN_PASSWORD_LENGTH) {
throw PasswordValidationException("Wrong passwords")
}
}
}
14 changes: 11 additions & 3 deletions src/main/kotlin/mate/academy/service/UserService.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package mate.academy.service

import mate.academy.exception.PasswordValidationException
import mate.academy.model.User

// This class represents a user service with user registration functionality
class UserService {

fun saveUser(user: User) : String {
fun saveUser(user: User): String {
// This is where you would typically save the user to a database
return "User ${user.username} saved successfully."
}

fun registerUser(username: String, password: String, repeatPassword: String) : String {

fun registerUser(username: String, password: String, repeatPassword: String): String {
try {
val passwordValidator = PasswordValidator()
passwordValidator.validate(password, repeatPassword)
val user = User(username, password)
return saveUser(user)
} catch (e: PasswordValidationException) {
return "Your passwords are incorrect. Try again."
}
}
}
Loading