Skip to content

Commit

Permalink
Enforce password strength constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0Ger committed Sep 14, 2022
1 parent 57a9cb1 commit 862035c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions selectel/resource_selectel_vpc_user_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package selectel

import (
"context"
"github.com/hashicorp/go-cty/cty"
"log"
"net/http"
"unicode"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -29,6 +31,29 @@ func resourceVPCUserV2() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
password := i.(string)
if len(password) < 8 {
return diag.Errorf("password must be at least 8 characters long")
}

chrType := 0
for _, r := range password {
switch {
case unicode.IsDigit(r):
chrType |= 1
case unicode.IsLower(r):
chrType |= 2
case unicode.IsUpper(r):
chrType |= 4
}
}
if chrType != 7 {
return diag.Errorf("password must contain at least one digit, one lowercase and one uppercase character")
}

return nil
},
},
"enabled": {
Type: schema.TypeBool,
Expand Down

0 comments on commit 862035c

Please sign in to comment.