Skip to content

PSAvoidUsingUserNameAndPasswordParams should not flag boolean/switch type password parameter #572

@kapilmb

Description

@kapilmb

For the following code snippet in a file called test1.ps1

function foo
{
    param(
    [string] $Username,
    [switch] $HidePassword
    )
}

PSScriptAnalyzer trips PSAvoidUserNameAndPasswordParams.

PS> Invoke-ScriptAnalyzer -Path C:\tmp\test1.ps1

RuleName                            Severity     FileName   Line  Message                                             
--------                            --------     --------   ----  -------                                             
PSAvoidUsingUserNameAndPassWordPara Error        test1.ps1  4     Function 'foo' has both Username and Password       
ms                                                                parameters. Either set the type of the Password     
                                                                  parameter to SecureString or replace the Username   
                                                                  and Password parameters with a Credential parameter 
                                                                  of type PSCredential. If using a Credential         
                                                                  parameter in PowerShell 4.0 or earlier, please      
                                                                  define a credential transformation attribute after  
                                                                  the PSCredential type attribute. 

In this case $HidePassword is clearly not intented to pass the password parameter and hence, this rule should ignore it.

Related issue: #571

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions