简体   繁体   English

Powershell 部分匹配字符串密码复杂性

[英]Powershell Partial Match Strings Password Complexity

I have two strings coming from a csv file:我有两个来自 csv 文件的字符串:

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

I'm trying to check for this: Not contain the user's account name or parts of the user's full name that exceed two consecutive characters.我正在尝试检查这一点:不包含用户的帐户名或超过两个连续字符的用户全名部分。

If 3 or more characters are matched I would like to add it here:如果匹配 3 个或更多字符,我想在此处添加:

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

Questions:问题:

  1. How do I match?我该如何匹配?

  2. How do I add to existing if statement.如何添加到现有的 if 语句。

Maybe it would be easier to run a function也许运行 function 会更容易

Since you dont really need to look for (more then) the minimum password / username match因为你真的不需要寻找(更多)最小密码/用户名匹配

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

This will return这将返回

22d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM