first commit
This commit is contained in:
commit
58b3df11f0
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Kotlin ###
|
||||
.kotlin
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
.idea/inspectionProfiles/Project_Default.xml
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
10
.idea/kotlinc.xml
Normal file
10
.idea/kotlinc.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinCommonCompilerArguments">
|
||||
<option name="apiVersion" value="2.0" />
|
||||
<option name="languageVersion" value="2.0" />
|
||||
</component>
|
||||
</project>
|
17
.idea/libraries/KotlinJavaRuntime.xml
Normal file
17
.idea/libraries/KotlinJavaRuntime.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime" type="repository">
|
||||
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib:2.0.21" />
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.21/kotlin-stdlib-2.0.21.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.21/kotlin-stdlib-2.0.21-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.21/kotlin-stdlib-2.0.21-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/authorization_test.iml" filepath="$PROJECT_DIR$/authorization_test.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
15
authorization_test.iml
Normal file
15
authorization_test.iml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
162
src/main/kotlin/Main.kt
Normal file
162
src/main/kotlin/Main.kt
Normal file
@ -0,0 +1,162 @@
|
||||
import model.AdminUser
|
||||
import model.ManagerUser
|
||||
import model.DefaultUser
|
||||
import model.User
|
||||
import java.time.LocalDate
|
||||
import javax.crypto.SecretKeyFactory
|
||||
import javax.crypto.spec.PBEKeySpec
|
||||
import java.util.Base64
|
||||
|
||||
|
||||
val authorizationList = mutableListOf<User>()
|
||||
|
||||
|
||||
private const val HASH_LENGTH = 256
|
||||
private const val ITERATIONS = 65536
|
||||
val salt = "sosalt"
|
||||
|
||||
|
||||
fun main() {
|
||||
while (true) {
|
||||
println("1) Регаться тут")
|
||||
println("2) Авторизироваться тут")
|
||||
var choice = readln()
|
||||
if (choice == "1") {
|
||||
authorizationList.add(registration())
|
||||
authorizationList.forEach{
|
||||
println(it.userId)
|
||||
println(it.login)
|
||||
println(it.password)
|
||||
println(it.email)
|
||||
println(it.lastAuthorizeDate)
|
||||
}
|
||||
}
|
||||
else {
|
||||
println(authorization())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun hashPassword(password: String, salt: String): String {
|
||||
val saltBytes = Base64.getDecoder().decode(salt)
|
||||
val spec = PBEKeySpec(password.toCharArray(), saltBytes, ITERATIONS, HASH_LENGTH)
|
||||
val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256")
|
||||
val hash = factory.generateSecret(spec).encoded
|
||||
return Base64.getEncoder().encodeToString(hash)
|
||||
}
|
||||
|
||||
|
||||
fun registration(): User{
|
||||
println("Почту пиши")
|
||||
val user_Email = readlnOrNull()
|
||||
checkNotNull(user_Email)
|
||||
require(user_Email.contains("@")) {
|
||||
"Добавь @"
|
||||
}
|
||||
|
||||
println("Пароль пиши")
|
||||
val user_Password = readlnOrNull()
|
||||
checkNotNull(user_Password)
|
||||
require(user_Password.length >= 8 &&
|
||||
user_Password.any { it.isDigit() } &&
|
||||
user_Password.any { it.isLetter() && it in 'a'..'z' || it in 'A'..'Z' }
|
||||
) {
|
||||
"Длинее делай или цифру/букву добавляй"
|
||||
}
|
||||
|
||||
println("Заново пароль пиши")
|
||||
val user_Password1 = readlnOrNull()
|
||||
checkNotNull(user_Password1)
|
||||
require(user_Password1 == user_Password) {
|
||||
"Ну ты и тупорылый"
|
||||
}
|
||||
|
||||
println("Логин пиши")
|
||||
val user_Login = readlnOrNull()
|
||||
checkNotNull(user_Login)
|
||||
require(user_Login.length >= 4) {
|
||||
"Длинее делай"
|
||||
}
|
||||
|
||||
|
||||
println("ТЫ КТО? 1) лох 2) админо 3) манагер")
|
||||
val role = readlnOrNull()
|
||||
checkNotNull(role)
|
||||
|
||||
return when(role) {
|
||||
"1" -> return DefaultUser(
|
||||
userId = authorizationList.size + 1,
|
||||
login = user_Login,
|
||||
password = hashPassword(user_Password, salt),
|
||||
email = user_Email,
|
||||
lastAuthorizeDate = LocalDate.now()
|
||||
)
|
||||
|
||||
"2" -> return AdminUser(
|
||||
userId = authorizationList.size + 1,
|
||||
login = user_Login,
|
||||
password = hashPassword(user_Password, salt),
|
||||
email = user_Email,
|
||||
lastAuthorizeDate = LocalDate.now()
|
||||
)
|
||||
|
||||
"3" -> return ManagerUser(
|
||||
userId = authorizationList.size + 1,
|
||||
login = user_Login,
|
||||
password = hashPassword(user_Password, salt),
|
||||
email = user_Email,
|
||||
lastAuthorizeDate = LocalDate.now()
|
||||
)
|
||||
|
||||
else -> { throw IllegalArgumentException("error") }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun authorization(): String{
|
||||
var adminFlg = true
|
||||
println("Почту пиши")
|
||||
val user_Email = readlnOrNull()
|
||||
checkNotNull(user_Email)
|
||||
val user = authorizationList.find { it.email == user_Email }
|
||||
require(user != null) {
|
||||
"нет такого"
|
||||
}
|
||||
|
||||
println("Пароль пиши")
|
||||
val user_Password = readlnOrNull()
|
||||
checkNotNull(user_Password)
|
||||
require(user.password == hashPassword(user_Password, salt)) {
|
||||
"не то"
|
||||
}
|
||||
|
||||
if (user is AdminUser) {
|
||||
while (adminFlg == true) {
|
||||
adminFlg = adminFunctional(user)
|
||||
}
|
||||
}
|
||||
|
||||
return "такой есть"
|
||||
}
|
||||
|
||||
|
||||
fun adminFunctional(user: AdminUser): Boolean {
|
||||
println("1) Показать всех")
|
||||
println("2) Показать всех сорт")
|
||||
println("3) Поменять пароль")
|
||||
println("4) Удалить чела")
|
||||
println("5) Пока")
|
||||
|
||||
var flg = readln()
|
||||
when(flg) {
|
||||
"1" -> user.allUsers(authorizationList)
|
||||
"2" -> user.allUsersSort(authorizationList)
|
||||
"3" -> user.updateUserPassword(authorizationList)
|
||||
"4" -> user.removeUser(authorizationList)
|
||||
"5" -> return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
51
src/main/kotlin/model/AdminUser.kt
Normal file
51
src/main/kotlin/model/AdminUser.kt
Normal file
@ -0,0 +1,51 @@
|
||||
package model
|
||||
|
||||
import hashPassword
|
||||
import salt
|
||||
import java.time.LocalDate
|
||||
|
||||
class AdminUser(
|
||||
userId: Int,
|
||||
login: String,
|
||||
password: String,
|
||||
email: String,
|
||||
lastAuthorizeDate: LocalDate,
|
||||
): User(userId, login, password, email, lastAuthorizeDate), IAdminUser {
|
||||
|
||||
override fun allUsers(authorizationList: MutableList<User>) {
|
||||
for (user in authorizationList) {
|
||||
println(user.login)
|
||||
}
|
||||
}
|
||||
|
||||
override fun allUsersSort(authorizationList: MutableList<User>) {
|
||||
authorizationList.sortByDescending { it.lastAuthorizeDate }
|
||||
for (user in authorizationList) {
|
||||
println(user.login + " зашел в " + user.lastAuthorizeDate)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateUserPassword(authorizationList: MutableList<User>) {
|
||||
println("Почту пиши для апдейта")
|
||||
val email = readln()
|
||||
println("Пароль пиши для апдейта")
|
||||
val password = readln()
|
||||
|
||||
val user = authorizationList.find { it.email == email }
|
||||
require(user != null) {
|
||||
"нет такого"
|
||||
}
|
||||
|
||||
user.password = hashPassword(password, salt)
|
||||
}
|
||||
|
||||
override fun removeUser(authorizationList: MutableList<User>) {
|
||||
println("Почту пиши для апдейта")
|
||||
val email = readln()
|
||||
|
||||
val removed = authorizationList.removeIf { it.email == email }
|
||||
if (removed) {
|
||||
println("удалили")
|
||||
} else { println("не удалили") }
|
||||
}
|
||||
}
|
11
src/main/kotlin/model/DefaultUser.kt
Normal file
11
src/main/kotlin/model/DefaultUser.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import java.time.LocalDate
|
||||
|
||||
class DefaultUser(
|
||||
userId: Int,
|
||||
login: String,
|
||||
password: String,
|
||||
email: String,
|
||||
lastAuthorizeDate: LocalDate,
|
||||
): User(userId, login, password, email, lastAuthorizeDate)
|
8
src/main/kotlin/model/IAdminUser.kt
Normal file
8
src/main/kotlin/model/IAdminUser.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package model
|
||||
|
||||
interface IAdminUser {
|
||||
fun allUsers(authorizationList: MutableList<User>)
|
||||
fun allUsersSort(authorizationList: MutableList<User>)
|
||||
fun updateUserPassword(authorizationList: MutableList<User>)
|
||||
fun removeUser(authorizationList: MutableList<User>)
|
||||
}
|
11
src/main/kotlin/model/ManagerUser.kt
Normal file
11
src/main/kotlin/model/ManagerUser.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import java.time.LocalDate
|
||||
|
||||
class ManagerUser(
|
||||
userId: Int,
|
||||
login: String,
|
||||
password: String,
|
||||
email: String,
|
||||
lastAuthorizeDate: LocalDate,
|
||||
): User(userId, login, password, email, lastAuthorizeDate)
|
11
src/main/kotlin/model/User.kt
Normal file
11
src/main/kotlin/model/User.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import java.time.LocalDate
|
||||
|
||||
open class User(
|
||||
val userId: Int,
|
||||
val login: String,
|
||||
var password: String,
|
||||
var email: String,
|
||||
var lastAuthorizeDate: LocalDate,
|
||||
)
|
Loading…
Reference in New Issue
Block a user