Skip to content

Commit 6425780

Browse files
authored
added yubikey PIN characters validator (#220)
* added yubikey password characters validator * replaced 'password' to 'PIN'
1 parent ea6996d commit 6425780

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/main/kotlin/com/vk/admstorm/ssh/EnterPasswordDialog.kt

+29-9
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package com.vk.admstorm.ssh
22

33
import com.intellij.openapi.project.Project
44
import com.intellij.openapi.ui.DialogWrapper
5+
import com.intellij.ui.JBColor
56
import com.intellij.ui.components.JBCheckBox
67
import com.intellij.ui.components.JBPasswordField
78
import com.intellij.ui.dsl.builder.AlignX
89
import com.intellij.ui.dsl.builder.BottomGap
910
import com.intellij.ui.dsl.builder.TopGap
1011
import com.intellij.ui.dsl.builder.panel
1112
import com.intellij.util.ui.JBDimension
13+
import java.awt.event.KeyAdapter
14+
import java.awt.event.KeyEvent
1215
import javax.swing.JComponent
16+
import javax.swing.JLabel
1317
import javax.swing.JPanel
1418

1519
class EnterPasswordDialog(project: Project) : DialogWrapper(project, true, IdeModalityType.PROJECT) {
@@ -25,38 +29,54 @@ class EnterPasswordDialog(project: Project) : DialogWrapper(project, true, IdeMo
2529
}
2630
}
2731

28-
private var myPasswordInput = JBPasswordField()
29-
private val myRememberCheckBox = JBCheckBox("Remember", true)
32+
private var passwordInput = JBPasswordField()
33+
private val rememberCheckBox = JBCheckBox("Remember", true)
34+
private val warningLabel = JLabel().apply { foreground = JBColor.RED }
3035

31-
fun getPassword() = String(myPasswordInput.password)
32-
fun isRemember() = myRememberCheckBox.isSelected
36+
fun getPassword() = String(passwordInput.password)
37+
fun isRemember() = rememberCheckBox.isSelected
3338

3439
init {
35-
title = "Enter Password"
40+
title = "Enter PIN"
3641

3742
init()
43+
44+
passwordInput.addKeyListener(object : KeyAdapter() {
45+
override fun keyReleased(e: KeyEvent) {
46+
if (getPassword().any { it in 'А'..'я' || it == 'ё' || it == 'Ё' }) {
47+
warningLabel.text = "PIN should contain only English characters and numbers!"
48+
} else {
49+
warningLabel.text = ""
50+
}
51+
}
52+
})
3853
}
3954

40-
override fun getPreferredFocusedComponent() = myPasswordInput
55+
override fun getPreferredFocusedComponent() = passwordInput
4156

4257
override fun createSouthAdditionalPanel(): JPanel {
4358
return panel {
4459
row {
45-
cell(myRememberCheckBox)
60+
cell(rememberCheckBox)
4661
}
4762
}
4863
}
4964

5065
override fun createCenterPanel(): JComponent {
5166
return panel {
5267
row {
53-
label("Enter password for Yubikey:")
68+
label("Enter PIN for Yubikey:")
5469
}.topGap(TopGap.NONE)
5570

5671
row {
57-
cell(myPasswordInput)
72+
cell(passwordInput)
5873
.align(AlignX.FILL)
5974
}.bottomGap(BottomGap.NONE)
75+
76+
row{
77+
cell(warningLabel)
78+
}.bottomGap(BottomGap.NONE)
79+
6080
}.apply {
6181
preferredSize = JBDimension(300, -1)
6282
}

0 commit comments

Comments
 (0)