Can Powershell check passwords against a dictionary?

This topic contains 2 replies, has 2 voices, and was last updated by  Ali Hassan 3 months, 3 weeks ago.

  • Author
    Posts
  • #73909

    Ali Hassan
    Participant

    Hi Guys,

    We all know that user passwords are vulnerable, simply because they arent complex enough. What I am attempting to do is write a simple enough script to have a password as an input and then give it points to see if its strong enough. I call it my lucky six game and the idea is to score all 7 points. One last check that I want to do is to have the entered password validate against a dictionary to see if any common words are entered. I am not sure how I should go about this.. Does anyone have ideas? Below is my script so far..

    Import-Module ActiveDirectory
    $password = read-host "Please enter the password you want to test"
    $passlen = 8
    $score = 0
    if ($password.Length  -ge $passlen){
    if ($password -match "[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]"){
    
    $score++
    
    } #1
    
    
    if($password -cmatch "[A-Z]"){
    
    $score++
    
    } #2
    
    if($password -cmatch "[a-z]"){
    
    $score++
    
    } #3
    
    if($password -match "[0-9]"){
    
    $score++
    
    } #4
    
    if($password[0] -match "[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]"){
    
    $score++
    
    } #5
    
    if($password[-1] -match "[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]"){
    
    $score++
    
    } #6
    
    if($password.Length -le 15){
    
    $score--
    
    }
    
    if($password.ToCharArray() | Group | Select Count | Where -Property Count -ne 1)
    { 
        $score--
    
    } 
    
    } # end for password.length loop
    
    else{
    
    write-output "The minimum length of the password is $passlen "
    
    }
    
    write-output "Your password score is $score out of 6!"
    
    
  • #73918

    Max Kozlov
    Participant

    The stright solution would be to use an array
    something like this

    $pwds = Get-Content d:\passwords
    #[...]
    
    $found = $false
    foreach ($p in $pwds) {
      if ($password -match $p) { $found = $true; break }
    }
    if (! $found) {
      $score++
    }
    

You must be logged in to reply to this topic.