init
This commit is contained in:
parent
5adc4b47be
commit
2f1714eeaa
23
src/main/kotlin/RepositoryImpl/AuthorizeRepositoryImpl.kt
Normal file
23
src/main/kotlin/RepositoryImpl/AuthorizeRepositoryImpl.kt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package RepositoryImpl
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import authorizeList
|
||||||
|
|
||||||
|
fun authorization(){
|
||||||
|
println()
|
||||||
|
println()
|
||||||
|
println()
|
||||||
|
var check =true
|
||||||
|
while(check) {
|
||||||
|
println("Введите почту или номер телефона для авторизации")
|
||||||
|
val readUserEmailOrNumber = readln()
|
||||||
|
println("Введите пароль")
|
||||||
|
val readUserPassword = readln()
|
||||||
|
authorizeList.forEach {
|
||||||
|
if ((readUserEmailOrNumber == it.email || readUserEmailOrNumber == it.phone) && hashing(readUserPassword) == it.password) {
|
||||||
|
it.lastAuthorizeDate = LocalDate.now()
|
||||||
|
check=false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
src/main/kotlin/RepositoryImpl/PasswordRepositoryImpl.kt
Normal file
15
src/main/kotlin/RepositoryImpl/PasswordRepositoryImpl.kt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package RepositoryImpl
|
||||||
|
|
||||||
|
import javax.crypto.SecretKey
|
||||||
|
import javax.crypto.SecretKeyFactory
|
||||||
|
import javax.crypto.spec.PBEKeySpec
|
||||||
|
|
||||||
|
fun hashing(password : String): SecretKey? {
|
||||||
|
val salt = byteArrayOf(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f)
|
||||||
|
val iterations = 10000
|
||||||
|
val keySize = 256
|
||||||
|
val keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
|
||||||
|
val keySpec = PBEKeySpec(password.toCharArray(), salt, iterations, keySize)
|
||||||
|
val secretKey = keyFactory.generateSecret(keySpec)
|
||||||
|
return secretKey
|
||||||
|
}
|
68
src/main/kotlin/RepositoryImpl/RegistrationRepositoryImpl.kt
Normal file
68
src/main/kotlin/RepositoryImpl/RegistrationRepositoryImpl.kt
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package RepositoryImpl
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import model.User
|
||||||
|
import RepositoryImpl.hashing
|
||||||
|
|
||||||
|
fun registration() : User {
|
||||||
|
var userLogin = ""
|
||||||
|
while (userLogin?.length!! <4){
|
||||||
|
print("Введите никнейм: ")
|
||||||
|
userLogin = readln()
|
||||||
|
if (userLogin.length<4){
|
||||||
|
println("Никнейм должен быть больше 4 символов. Попробуйте снова")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var userPassword = ""
|
||||||
|
var dig = 0
|
||||||
|
var let = 0
|
||||||
|
while (userPassword.length<8 || dig<1 || let<1){
|
||||||
|
println("Пароль должен быть не менее 8 символов и должен содеражть буквы и цифры")
|
||||||
|
print("Введите пароль: ")
|
||||||
|
userPassword = readln()
|
||||||
|
dig=0
|
||||||
|
let=0
|
||||||
|
userPassword.forEach {
|
||||||
|
if(it.isDigit()){
|
||||||
|
dig+=1
|
||||||
|
}
|
||||||
|
else if (it.isLetter()){
|
||||||
|
let+=1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Повторите пароль: ")
|
||||||
|
var secondUserPassword = ""
|
||||||
|
while (secondUserPassword != userPassword) {
|
||||||
|
secondUserPassword = readln()
|
||||||
|
checkNotNull(secondUserPassword)
|
||||||
|
if (secondUserPassword != userPassword) {
|
||||||
|
println("Пароли не совпадают. Повторите попытку")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var hashUserPassword= hashing(userPassword)
|
||||||
|
var userEmail=""
|
||||||
|
while (!("@" in userEmail)){
|
||||||
|
print("Введите почту: ")
|
||||||
|
userEmail= readln()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var userPhone = "1234"
|
||||||
|
while(!((userPhone.startsWith("89") && userPhone.length == 11) || (userPhone.startsWith("+7") && userPhone.length == 12))) {
|
||||||
|
print("Введите номер телефона: ")
|
||||||
|
userPhone = readln()
|
||||||
|
}
|
||||||
|
|
||||||
|
return User(
|
||||||
|
authorizeList.size + 1,
|
||||||
|
password = hashUserPassword,
|
||||||
|
login = userLogin,
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
email = userEmail,
|
||||||
|
phone = userPhone,
|
||||||
|
role = role
|
||||||
|
)
|
||||||
|
}
|
@ -1,114 +1,103 @@
|
|||||||
import model.UserAuthorize
|
import java.io.Console
|
||||||
import model.Roles
|
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
|
||||||
import javax.crypto.SecretKey
|
import javax.crypto.SecretKey
|
||||||
import javax.crypto.SecretKeyFactory
|
import javax.crypto.SecretKeyFactory
|
||||||
import javax.crypto.spec.PBEKeySpec
|
import javax.crypto.spec.PBEKeySpec
|
||||||
import javax.swing.text.PasswordView
|
import javax.swing.text.PasswordView
|
||||||
|
import RepositoryImpl.hashing
|
||||||
|
import RepositoryImpl.registration
|
||||||
|
import RepositoryImpl.authorization
|
||||||
|
import model.User
|
||||||
|
|
||||||
val authorizeList = mutableListOf<UserAuthorize>()
|
val authorizeList = mutableListOf<User>()
|
||||||
fun main() {
|
fun main() {
|
||||||
authorizeList.add(registration())
|
authorizeList.add(registration())
|
||||||
|
authorizeList.add(User(
|
||||||
|
2, "Alex", hashing("Alex1234"), "alex@gmail.com", "89310010543",
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
))
|
||||||
|
authorizeList.add(User(
|
||||||
|
3, "MegaBalbes", hashing("fjghk123j"), "sdfgtyghk@gmail.com", "89314230543",
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
))
|
||||||
|
authorizeList.add(User(
|
||||||
|
4, "IVBan", hashing("d,lfmk123454sdjhy"), "dsfgxvds@gmail.com", "+79310864309",
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
))
|
||||||
|
authorizeList.add(User(
|
||||||
|
5, "Vlad", hashing("dfghfgd7878"), "rthtre6@gmail.com", "89311054819",
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
))
|
||||||
|
authorizeList.add(User(
|
||||||
|
6, "XDel", hashing("sadfhjh1235"), "kjhndfjhv@gmail.com", "89319654812",
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
))
|
||||||
|
authorizeList.add(User(
|
||||||
|
7, "Amega", hashing("123dfgyt"), "lljseioev@gmail.com", "89313218457",
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
))
|
||||||
|
authorizeList.add(User(
|
||||||
|
8, "Orbita", hashing("98547kxdbfg"), "mlkswgjb@gmail.com", "89319784561",
|
||||||
|
lastAuthorizeDate = LocalDate.now(),
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
authorization()
|
authorization()
|
||||||
|
var check = true
|
||||||
|
while(check){
|
||||||
|
println("1. Войти в админ-панель")
|
||||||
|
println("2. Выход")
|
||||||
|
var answer= readln()
|
||||||
|
when(answer){
|
||||||
|
"1" -> admin()
|
||||||
|
"2" -> check = false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun admin(){
|
||||||
|
while(true){
|
||||||
|
println("1. Вывести всех пользователей")
|
||||||
|
println("2. Поменять пароль пользователя")
|
||||||
|
println("3. Удалить пользователя")
|
||||||
|
println("4. Вывести всех пользователей с сортировкой по дате")
|
||||||
|
var answer = readln()
|
||||||
|
when(answer){
|
||||||
|
"1" -> authorizeList.forEach(){
|
||||||
|
println("ID: " + it.userId)
|
||||||
|
println("Ник: " + it.login)
|
||||||
|
println("Пароль: " + it.password?.encoded)
|
||||||
|
println("Email: " + it.email)
|
||||||
|
println("Телефон: " + it.phone)
|
||||||
|
println("Role: " + it.role)
|
||||||
|
println("Последняя авторизация: " + it.lastAuthorizeDate)
|
||||||
|
}
|
||||||
|
"2" -> println()
|
||||||
|
"3" -> println()
|
||||||
|
"4" -> println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun authorization(){
|
fun authorization(){
|
||||||
println()
|
println()
|
||||||
println()
|
println()
|
||||||
println()
|
println()
|
||||||
|
var check =true
|
||||||
|
while(check) {
|
||||||
println("Введите почту или номер телефона для авторизации")
|
println("Введите почту или номер телефона для авторизации")
|
||||||
val readUserEmailOrNumber = readln()
|
val readUserEmailOrNumber = readln()
|
||||||
println("Введите пароль")
|
println("Введите пароль")
|
||||||
val readUserPassword = readln()
|
val readUserPassword = readln()
|
||||||
authorizeList.forEach{
|
authorizeList.forEach {
|
||||||
if ((readUserEmailOrNumber==it.email || readUserEmailOrNumber==it.phone) && hashing(readUserPassword)==it.password){
|
if ((readUserEmailOrNumber == it.email || readUserEmailOrNumber == it.phone) && hashing(readUserPassword) == it.password) {
|
||||||
it.lastAuthorizeDate= LocalDateTime.now()
|
it.lastAuthorizeDate = LocalDate.now()
|
||||||
return println(it.role.roleName +"\r\n"+it.lastAuthorizeDate)
|
check=false
|
||||||
|
return println(it.role + "\r\n" + it.lastAuthorizeDate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hashing(password : String): SecretKey? {
|
|
||||||
val salt = byteArrayOf(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f)
|
|
||||||
val iterations = 10000
|
|
||||||
val keySize = 256
|
|
||||||
val keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
|
|
||||||
val keySpec = PBEKeySpec(password.toCharArray(), salt, iterations, keySize)
|
|
||||||
val secretKey = keyFactory.generateSecret(keySpec)
|
|
||||||
return secretKey
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun registration() : UserAuthorize {
|
|
||||||
var userLogin = ""
|
|
||||||
while (userLogin?.length!! <4){
|
|
||||||
print("Введите никнейм: ")
|
|
||||||
userLogin = readln()
|
|
||||||
if (userLogin.length<4){
|
|
||||||
println("Никнейм должен быть больше 4 символов. Попробуйте снова")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var userPassword = ""
|
|
||||||
var dig = 0
|
|
||||||
var let = 0
|
|
||||||
while (userPassword.length<8 && dig<1 && let<1){
|
|
||||||
println("Пароль должен быть не менее 8 символов и должен содеражть буквы и цифры")
|
|
||||||
print("Введите пароль: ")
|
|
||||||
dig=0
|
|
||||||
let=0
|
|
||||||
userPassword = readln()
|
|
||||||
userPassword.forEach {
|
|
||||||
if(it.isDigit()){
|
|
||||||
dig++
|
|
||||||
}
|
|
||||||
else if (it.isLetter()){
|
|
||||||
let++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userPassword.forEach {
|
|
||||||
require(it.isLetterOrDigit())
|
|
||||||
require(userPassword.length >= 8)
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Повторите пароль: ")
|
|
||||||
var secondUserPassword = ""
|
|
||||||
while (secondUserPassword != userPassword) {
|
|
||||||
secondUserPassword = readln()
|
|
||||||
checkNotNull(secondUserPassword)
|
|
||||||
if (secondUserPassword != userPassword) {
|
|
||||||
println("Пароли не совпадают")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var hashUserPassword=hashing(userPassword)
|
|
||||||
|
|
||||||
print("Введите почту: ")
|
|
||||||
val userEmail = readlnOrNull()
|
|
||||||
checkNotNull(userEmail)
|
|
||||||
require("@" in userEmail)
|
|
||||||
|
|
||||||
print("Введите номер телефона: ")
|
|
||||||
var userPhone = readlnOrNull()
|
|
||||||
checkNotNull(userPhone)
|
|
||||||
require((userPhone.startsWith("89") && userPhone.length == 11) || (userPhone.startsWith("+7") && userPhone.length == 12))
|
|
||||||
print("Вы админ? (Y, N): ")
|
|
||||||
var role = Roles(1, "администратор")
|
|
||||||
var adm = readln()
|
|
||||||
if (adm!="Y"){
|
|
||||||
role = Roles(2, "пользователь")
|
|
||||||
}
|
|
||||||
|
|
||||||
return UserAuthorize(
|
|
||||||
authorizeList.size + 1,
|
|
||||||
password = hashUserPassword,
|
|
||||||
login = userLogin,
|
|
||||||
lastAuthorizeDate = LocalDateTime.now(),
|
|
||||||
email = userEmail,
|
|
||||||
phone = userPhone,
|
|
||||||
role = role
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
15
src/main/kotlin/model/AdminUser.kt
Normal file
15
src/main/kotlin/model/AdminUser.kt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import javax.crypto.SecretKey
|
||||||
|
|
||||||
|
class AdminUser(
|
||||||
|
userId: Int,
|
||||||
|
login: String,
|
||||||
|
password: SecretKey,
|
||||||
|
email: String,
|
||||||
|
phone: String,
|
||||||
|
lastAuthorizeDate: LocalDate
|
||||||
|
) : User(userId, login, password, email, phone, lastAuthorizeDate){
|
||||||
|
override val role: String = "администратор"
|
||||||
|
}
|
15
src/main/kotlin/model/DefaultUser.kt
Normal file
15
src/main/kotlin/model/DefaultUser.kt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import javax.crypto.SecretKey
|
||||||
|
|
||||||
|
class DefaultUser(
|
||||||
|
userId: Int,
|
||||||
|
login: String,
|
||||||
|
password: SecretKey,
|
||||||
|
email: String,
|
||||||
|
phone: String,
|
||||||
|
lastAuthorizeDate: LocalDate
|
||||||
|
) : User(userId, login, password,email, phone, lastAuthorizeDate) {
|
||||||
|
override val role: String = "пользователь"
|
||||||
|
}
|
15
src/main/kotlin/model/ManagerUser.kt
Normal file
15
src/main/kotlin/model/ManagerUser.kt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import javax.crypto.SecretKey
|
||||||
|
|
||||||
|
class ManagerUser(
|
||||||
|
userId: Int,
|
||||||
|
login: String,
|
||||||
|
password: SecretKey,
|
||||||
|
email: String,
|
||||||
|
phone: String,
|
||||||
|
lastAuthorizeDate: LocalDate
|
||||||
|
) : User(userId, login, password, email, phone, lastAuthorizeDate) {
|
||||||
|
override val role: String = "менеджер"
|
||||||
|
}
|
@ -1,6 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
data class Roles(
|
|
||||||
val roleId : Int,
|
|
||||||
val roleName : String
|
|
||||||
)
|
|
13
src/main/kotlin/model/User.kt
Normal file
13
src/main/kotlin/model/User.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import javax.crypto.SecretKey
|
||||||
|
|
||||||
|
open class User(
|
||||||
|
val userId: Int,
|
||||||
|
val login: String,
|
||||||
|
var password: SecretKey?,
|
||||||
|
var email: String,
|
||||||
|
var phone: String,
|
||||||
|
var lastAuthorizeDate: LocalDate
|
||||||
|
) { open val role: String = "пользователь"}
|
@ -1,15 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import java.time.LocalDate
|
|
||||||
import java.time.LocalDateTime
|
|
||||||
import javax.crypto.SecretKey
|
|
||||||
|
|
||||||
data class UserAuthorize(
|
|
||||||
val userId : Int,
|
|
||||||
val login : String,
|
|
||||||
var password : SecretKey?,
|
|
||||||
var email : String,
|
|
||||||
var phone : String,
|
|
||||||
var role : Roles,
|
|
||||||
var lastAuthorizeDate : LocalDateTime
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user