mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-01-07 00:49:46 -06:00
when creating password is now possible to add blank spaces for extra entropy, ref issue 755 (#787)
Co-authored-by: Yogesh Choudhary Paliyal <paliyalyogesh@gmail.com>
This commit is contained in:
@@ -47,7 +47,8 @@ class GeneratePasswordViewModel @Inject constructor(
|
||||
includeUpperCaseLetters = currentViewState.includeUppercaseLetters,
|
||||
includeLowerCaseLetters = currentViewState.includeLowercaseLetters,
|
||||
includeSymbols = currentViewState.includeSymbols,
|
||||
includeNumbers = currentViewState.includeNumbers
|
||||
includeNumbers = currentViewState.includeNumbers,
|
||||
includeBlankSpaces = currentViewState.includeBlankSpaces
|
||||
)
|
||||
|
||||
_viewState.update {
|
||||
@@ -86,6 +87,12 @@ class GeneratePasswordViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun onBlankSpacesCheckedChange(checked: Boolean) {
|
||||
_viewState.update {
|
||||
it.copy(includeBlankSpaces = checked)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
private fun observeState(context: Context) {
|
||||
viewModelScope.launch {
|
||||
@@ -97,4 +104,5 @@ class GeneratePasswordViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ data class GeneratePasswordViewState(
|
||||
val includeLowercaseLetters: Boolean,
|
||||
val includeSymbols: Boolean,
|
||||
val includeNumbers: Boolean,
|
||||
val password: String
|
||||
) {
|
||||
val includeBlankSpaces: Boolean,
|
||||
val password: String) {
|
||||
companion object {
|
||||
val Initial = GeneratePasswordViewState(
|
||||
length = DEFAULT_PASSWORD_LENGTH,
|
||||
@@ -17,6 +17,7 @@ data class GeneratePasswordViewState(
|
||||
includeLowercaseLetters = true,
|
||||
includeSymbols = true,
|
||||
includeNumbers = true,
|
||||
includeBlankSpaces = true,
|
||||
password = ""
|
||||
)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ fun GeneratePasswordContent(
|
||||
onUppercaseCheckedChange: (Boolean) -> Unit,
|
||||
onLowercaseCheckedChange: (Boolean) -> Unit,
|
||||
onNumbersCheckedChange: (Boolean) -> Unit,
|
||||
onSymbolsCheckedChange: (Boolean) -> Unit
|
||||
onSymbolsCheckedChange: (Boolean) -> Unit,
|
||||
onBlankSpacesCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
Scaffold(
|
||||
floatingActionButton = { GeneratePasswordFab(onGeneratePasswordClick) }
|
||||
@@ -54,7 +55,8 @@ fun GeneratePasswordContent(
|
||||
onUppercaseCheckedChange = onUppercaseCheckedChange,
|
||||
onLowercaseCheckedChange = onLowercaseCheckedChange,
|
||||
onNumbersCheckedChange = onNumbersCheckedChange,
|
||||
onSymbolsCheckedChange = onSymbolsCheckedChange
|
||||
onSymbolsCheckedChange = onSymbolsCheckedChange,
|
||||
onBlankSpacesCheckedChange = onBlankSpacesCheckedChange
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -81,7 +83,8 @@ private fun FormInputCard(
|
||||
onUppercaseCheckedChange: (Boolean) -> Unit,
|
||||
onLowercaseCheckedChange: (Boolean) -> Unit,
|
||||
onNumbersCheckedChange: (Boolean) -> Unit,
|
||||
onSymbolsCheckedChange: (Boolean) -> Unit
|
||||
onSymbolsCheckedChange: (Boolean) -> Unit,
|
||||
onBlankSpacesCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
OutlinedCard(
|
||||
colors = CardDefaults.outlinedCardColors(),
|
||||
@@ -105,6 +108,9 @@ private fun FormInputCard(
|
||||
NumberInput(viewState.includeNumbers, onNumbersCheckedChange)
|
||||
|
||||
SymbolInput(viewState.includeSymbols, onSymbolsCheckedChange)
|
||||
|
||||
BlankSpaceInput(viewState.includeBlankSpaces, onBlankSpacesCheckedChange)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,6 +189,19 @@ private fun SymbolInput(
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BlankSpaceInput(
|
||||
includeBlankSpaces: Boolean,
|
||||
onBlankSpacesCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
CheckboxWithLabel(
|
||||
label = "Blank Spaces",
|
||||
checked = includeBlankSpaces,
|
||||
onCheckedChange = onBlankSpacesCheckedChange
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@Preview(
|
||||
name = "Night Mode",
|
||||
uiMode = Configuration.UI_MODE_NIGHT_YES
|
||||
@@ -205,7 +224,8 @@ private fun GeneratePasswordContentPreview() {
|
||||
onUppercaseCheckedChange = {},
|
||||
onLowercaseCheckedChange = {},
|
||||
onNumbersCheckedChange = {},
|
||||
onSymbolsCheckedChange = {}
|
||||
onSymbolsCheckedChange = {},
|
||||
onBlankSpacesCheckedChange = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ fun GeneratePasswordScreen(viewModel: GeneratePasswordViewModel) {
|
||||
onUppercaseCheckedChange = viewModel::onUppercaseCheckedChange,
|
||||
onLowercaseCheckedChange = viewModel::onLowercaseCheckedChange,
|
||||
onNumbersCheckedChange = viewModel::onNumbersCheckedChange,
|
||||
onSymbolsCheckedChange = viewModel::onSymbolsCheckedChange
|
||||
onSymbolsCheckedChange = viewModel::onSymbolsCheckedChange,
|
||||
onBlankSpacesCheckedChange = viewModel::onBlankSpacesCheckedChange
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,17 @@ class PasswordGenerator(
|
||||
private var includeUpperCaseLetters: Boolean,
|
||||
private var includeLowerCaseLetters: Boolean,
|
||||
private var includeSymbols: Boolean,
|
||||
private var includeNumbers: Boolean
|
||||
private var includeNumbers: Boolean,
|
||||
private var includeBlankSpaces: Boolean
|
||||
) {
|
||||
|
||||
constructor() : this(10, true, true, true, true)
|
||||
constructor() : this(10, true, true, true, true, true)
|
||||
|
||||
private val UPPER_CASE = 0
|
||||
private val LOWER_CASE = 1
|
||||
private val NUMBERS = 2
|
||||
private val SYMBOLS = 3
|
||||
private val BLANKSPACES = 4
|
||||
|
||||
fun generatePassword(): String {
|
||||
var password = ""
|
||||
@@ -31,6 +33,10 @@ class PasswordGenerator(
|
||||
list.add(SYMBOLS)
|
||||
}
|
||||
|
||||
if (includeBlankSpaces) {
|
||||
list.add(BLANKSPACES)
|
||||
}
|
||||
|
||||
for (i in 1..length) {
|
||||
if (list.isNotEmpty()) {
|
||||
when (list.random()) {
|
||||
@@ -38,6 +44,7 @@ class PasswordGenerator(
|
||||
LOWER_CASE -> password += ('a'..'z').random().toString()
|
||||
NUMBERS -> password += ('0'..'9').random().toString()
|
||||
SYMBOLS -> password += listOf('!', '@', '#', '$', '%', '&', '*', '+', '=', '-', '~', '?', '/', '_').random().toString()
|
||||
BLANKSPACES -> password += (' ').toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user