Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce password strength constraint #209

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4,7 +4,9 @@ import (
"context"
"log"
"net/http"
"unicode"

"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/users"
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