【问题标题】:Powershell Partial Match Strings Password ComplexityPowershell 部分匹配字符串密码复杂性
【发布时间】:2020-08-04 14:27:03
【问题描述】:

我有两个来自 csv 文件的字符串:

$Password = "dkjhfd22dnrhfg"
$Username = "NewUser22d"

我正在尝试检查这一点: 不包含超过两个连续字符的用户帐户名或用户全名部分。

如果匹配 3 个或更多字符,我想在此处添加:

if(($password -cmatch '[a-z]') -and ($password -cmatch '[A-Z]') -and ($password -match '\d') -and (($password).length -ge 18))

问题:

  1. 如何匹配?

  2. 如何添加到现有的 if 语句。

【问题讨论】:

    标签: string powershell string-matching


    【解决方案1】:

    也许运行一个函数会更容易

    因为你真的不需要寻找(更多)最小密码/用户名匹配

    Function Check-Password{
        param(
            [string]$Username,
            [string]$Password,
            [int]$MatchLength
        )
        for($i = 0; $i -ne ($Username.Length - ($MatchLength - 1)); $i++){
            $Username.Substring($i, $MatchLength) | Where-Object {$Password -like "*$_*"}
        }
    }
    
    Check-Password -Username "NewUser22d" -Password "dkjhfd22dnrhfg" -MatchLength 3
    

    这将返回

    22d
    

    【讨论】:

      猜你喜欢
      • 2022-08-11
      • 2014-06-19
      • 2017-12-25
      • 1970-01-01
      • 2015-04-14
      • 2012-06-15
      • 2019-10-18
      • 2017-07-02
      • 1970-01-01
      相关资源
      最近更新 更多