mattermost-community-enterp.../channels/app/import_utils.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

61 lines
1.6 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"crypto/rand"
"math/big"
)
const (
passwordSpecialChars = "!$%^&*(),."
passwordNumbers = "0123456789"
passwordUpperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
passwordLowerCaseLetters = "abcdefghijklmnopqrstuvwxyz"
passwordAllChars = passwordSpecialChars + passwordNumbers + passwordUpperCaseLetters + passwordLowerCaseLetters
)
func randInt(maxInt int) (int, error) {
val, err := rand.Int(rand.Reader, big.NewInt(int64(maxInt)))
if err != nil {
return 0, err
}
return int(val.Int64()), nil
}
func generatePassword(minimumLength int) (string, error) {
upperIdx, err := randInt(len(passwordUpperCaseLetters))
if err != nil {
return "", err
}
numberIdx, err := randInt(len(passwordNumbers))
if err != nil {
return "", err
}
lowerIdx, err := randInt(len(passwordLowerCaseLetters))
if err != nil {
return "", err
}
specialIdx, err := randInt(len(passwordSpecialChars))
if err != nil {
return "", err
}
// Make sure we are guaranteed at least one of each type to meet any possible password complexity requirements.
password := string([]rune(passwordUpperCaseLetters)[upperIdx]) +
string([]rune(passwordNumbers)[numberIdx]) +
string([]rune(passwordLowerCaseLetters)[lowerIdx]) +
string([]rune(passwordSpecialChars)[specialIdx])
for len(password) < minimumLength {
i, err := randInt(len(passwordAllChars))
if err != nil {
return "", err
}
password = password + string([]rune(passwordAllChars)[i])
}
return password, nil
}