mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Implements generator cli for secrets (#3531)
Signed-off-by: Codruț Constantin Gușoi <codrut.gusoi@gmail.com>
This commit is contained in:
		
				
					committed by
					
						 Lauris BH
						Lauris BH
					
				
			
			
				
	
			
			
			
						parent
						
							e59fe7c8d9
						
					
				
				
					commit
					96c268c0fc
				
			| @@ -14,7 +14,6 @@ import ( | ||||
| 	"html/template" | ||||
| 	"io" | ||||
| 	"math" | ||||
| 	"math/big" | ||||
| 	"net/http" | ||||
| 	"net/url" | ||||
| 	"path" | ||||
| @@ -88,25 +87,6 @@ func BasicAuthEncode(username, password string) string { | ||||
| 	return base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) | ||||
| } | ||||
|  | ||||
| // GetRandomString generate random string by specify chars. | ||||
| func GetRandomString(n int) (string, error) { | ||||
| 	const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | ||||
|  | ||||
| 	buffer := make([]byte, n) | ||||
| 	max := big.NewInt(int64(len(alphanum))) | ||||
|  | ||||
| 	for i := 0; i < n; i++ { | ||||
| 		index, err := randomInt(max) | ||||
| 		if err != nil { | ||||
| 			return "", err | ||||
| 		} | ||||
|  | ||||
| 		buffer[i] = alphanum[index] | ||||
| 	} | ||||
|  | ||||
| 	return string(buffer), nil | ||||
| } | ||||
|  | ||||
| // GetRandomBytesAsBase64 generates a random base64 string from n bytes | ||||
| func GetRandomBytesAsBase64(n int) string { | ||||
| 	bytes := make([]byte, 32) | ||||
| @@ -119,15 +99,6 @@ func GetRandomBytesAsBase64(n int) string { | ||||
| 	return base64.RawURLEncoding.EncodeToString(bytes) | ||||
| } | ||||
|  | ||||
| func randomInt(max *big.Int) (int, error) { | ||||
| 	rand, err := rand.Int(rand.Reader, max) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
|  | ||||
| 	return int(rand.Int64()), nil | ||||
| } | ||||
|  | ||||
| // VerifyTimeLimitCode verify time limit code | ||||
| func VerifyTimeLimitCode(data string, minutes int, code string) bool { | ||||
| 	if len(code) <= 18 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user