MM-19553: Generate valid passwords on bulk import. (#12871)
This changes the bulk import so when it needs to generate a password because no password or auth data was supplied, it now takes into account the configured minimum length, as well as assuming all other distinct character types are configured to be required. It should now generate valid passwords regardless of the password policy configuration in the Mattermost configuration file.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f9a7a16a78
Коммит
1b95ee9834
@@ -9,10 +9,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/mattermost/mattermost-server/services/timezones"
|
||||
@@ -836,3 +838,27 @@ func UsersWithGroupsAndCountFromJson(data io.Reader) *UsersWithGroupsAndCount {
|
||||
json.Unmarshal(bodyBytes, uwg)
|
||||
return uwg
|
||||
}
|
||||
|
||||
var passwordRandomSource = rand.NewSource(time.Now().Unix())
|
||||
var passwordSpecialChars = "!$%^&*(),."
|
||||
var passwordNumbers = "0123456789"
|
||||
var passwordUpperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
var passwordLowerCaseLetters = "abcdefghijklmnopqrstuvwxyz"
|
||||
var passwordAllChars = passwordSpecialChars + passwordNumbers + passwordUpperCaseLetters + passwordLowerCaseLetters
|
||||
|
||||
func GeneratePassword(minimumLength int) string {
|
||||
r := rand.New(passwordRandomSource)
|
||||
|
||||
// Make sure we are guaranteed at least one of each type to meet any possible password complexity requirements.
|
||||
password := string([]rune(passwordUpperCaseLetters)[r.Intn(len(passwordUpperCaseLetters))]) +
|
||||
string([]rune(passwordNumbers)[r.Intn(len(passwordNumbers))]) +
|
||||
string([]rune(passwordLowerCaseLetters)[r.Intn(len(passwordLowerCaseLetters))]) +
|
||||
string([]rune(passwordSpecialChars)[r.Intn(len(passwordSpecialChars))])
|
||||
|
||||
for len(password) < minimumLength {
|
||||
i := r.Intn(len(passwordAllChars))
|
||||
password = password + string([]rune(passwordAllChars)[i])
|
||||
}
|
||||
|
||||
return password
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user