【问题标题】:Numeric pin length validation using powershell使用 powershell 验证数字引脚长度
【发布时间】:2022-12-24 23:20:38
【问题描述】:

我希望用户设置 bitlocker pin 和 pin 长度应该是 9 位数字,而不是像 123456789 这样的顺序。

我正在尝试的代码:-

$PIN = Read-Host -AsSecureString -Prompt 'Input your bitlocker PIN'

$SecureString = ConvertTo-SecureString $PIN -AsPlainText -Force

Enable-BitLocker -MountPoint "C:" -EncryptionMethod Aes256 -UsedSpaceOnly -Pin $SecureString -TPMandPinProtector

【问题讨论】:

  • 您允许在一个序列中的最大数字数量是多少?示例:123406070(连续 4 个数字)。你想让这个号码被允许吗?

标签: powershell


【解决方案1】:

此代码假定您不希望用户能够在其 pin 中包含 3 个或更多序列号。我们可以设置多个值来匹配,然后使用正则表达式将字符串匹配到列表中的任何值。

$sequence = @('012','123','234','345','456','567','678','789','987','876','765','654','543','432','321','210')
$sequenceRegex = [string]::Join('|', $sequence)

Do 
{ 

    $PIN = Read-Host -Prompt 'Input your PIN. Should be 9 digits and not contain a sequence of 3 or more numbers.'
}

While($PIN -match $sequenceRegex -or $PIN.Length -ne 9)

Write-Host $PIN  # just for example to confirm

$SecureString = ConvertTo-SecureString $PIN -AsPlainText -Force

Enable-BitLocker -MountPoint "C:" -EncryptionMethod Aes256 -UsedSpaceOnly -Pin $SecureString -TPMandPinProtector

【讨论】:

  • 通过'210','321', ...,'987' 按相反的顺序怎么样?
  • pin 的最小 9 位数字长度如何?
  • @SurajKumar 已更新以说明逆序并检查它是否为 9 位数字。
猜你喜欢
  • 2018-03-07
  • 2017-02-25
  • 2016-01-29
  • 2020-10-11
  • 1970-01-01
  • 1970-01-01
  • 2020-12-11
  • 2013-05-15
相关资源
最近更新 更多