init
This commit is contained in:
parent
df6cabbca0
commit
5adc4b47be
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,39 +1,80 @@
|
||||
import model.UserAuthorize
|
||||
import model.Roles
|
||||
import java.awt.Checkbox
|
||||
import java.security.SecureRandom
|
||||
import java.time.LocalDate
|
||||
import kotlin.system.exitProcess
|
||||
import java.time.LocalDateTime
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.SecretKeyFactory
|
||||
import javax.crypto.spec.PBEKeySpec
|
||||
import javax.swing.text.PasswordView
|
||||
|
||||
val authorizeList = mutableListOf<UserAuthorize>()
|
||||
fun main() {
|
||||
val userLogin = readlnOrNull()
|
||||
registration()
|
||||
authorizeList.add(registration())
|
||||
authorization()
|
||||
}
|
||||
|
||||
fun authorization(){
|
||||
println()
|
||||
println()
|
||||
println()
|
||||
println("Введите почту или номер телефона для авторизации")
|
||||
val readUserEmailOrNumber = readln()
|
||||
println("Введите пароль")
|
||||
val readUserPassword = readln()
|
||||
authorizeList.forEach{
|
||||
println()
|
||||
if ((readUserEmailOrNumber==it.email || readUserEmailOrNumber==it.phone) && hashing(readUserPassword)==it.password){
|
||||
it.lastAuthorizeDate= LocalDateTime.now()
|
||||
return println(it.role.roleName +"\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 {
|
||||
print("Введите никнейм: ")
|
||||
val userLogin = readlnOrNull()
|
||||
checkNotNull(userLogin)
|
||||
require(userLogin.length >= 4) {
|
||||
"Никнейм больше 4 символов"
|
||||
var userLogin = ""
|
||||
while (userLogin?.length!! <4){
|
||||
print("Введите никнейм: ")
|
||||
userLogin = readln()
|
||||
if (userLogin.length<4){
|
||||
println("Никнейм должен быть больше 4 символов. Попробуйте снова")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print("Введите пароль: ")
|
||||
val userPassword = readlnOrNull()
|
||||
checkNotNull(userPassword)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
println()
|
||||
print("Повторите пароль: ")
|
||||
var secondUserPassword = ""
|
||||
while (secondUserPassword != userPassword) {
|
||||
@ -43,27 +84,31 @@ fun registration() : UserAuthorize {
|
||||
println("Пароли не совпадают")
|
||||
}
|
||||
}
|
||||
var hashUserPassword=hashing(userPassword)
|
||||
|
||||
|
||||
println()
|
||||
print("Введите почту: ")
|
||||
val userEmail = readlnOrNull()
|
||||
checkNotNull(userEmail)
|
||||
require("@" in userEmail)
|
||||
|
||||
println()
|
||||
print("Введите номер телефона: ")
|
||||
var userPhone = readlnOrNull()
|
||||
checkNotNull(userPhone)
|
||||
require(userPhone.startsWith("89") && userPhone.length == 11)
|
||||
|
||||
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 = userPassword,
|
||||
password = hashUserPassword,
|
||||
login = userLogin,
|
||||
lastAuthorizeDate = LocalDate.now(),
|
||||
lastAuthorizeDate = LocalDateTime.now(),
|
||||
email = userEmail,
|
||||
phone = userPhone
|
||||
phone = userPhone,
|
||||
role = role
|
||||
)
|
||||
}
|
@ -1,12 +1,15 @@
|
||||
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 : String,
|
||||
var password : SecretKey?,
|
||||
var email : String,
|
||||
var phone : String,
|
||||
var lastAuthorizeDate : LocalDate
|
||||
var role : Roles,
|
||||
var lastAuthorizeDate : LocalDateTime
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user