mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Password Complexity Checks (#6230)
Add password complexity checks. The default settings require a lowercase, uppercase, number and a special character within passwords. Co-Authored-By: T-M-A <maxim.tkachenko@gmail.com> Co-Authored-By: Lanre Adelowo <adelowomailbox@gmail.com> Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-Authored-By: Lauris BH <lauris@nix.lv>
This commit is contained in:
		
				
					committed by
					
						
						zeripath
					
				
			
			
				
	
			
			
			
						parent
						
							f9aba9ba0f
						
					
				
				
					commit
					db657192d0
				
			@@ -6,9 +6,12 @@
 | 
			
		||||
package admin
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/modules/context"
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
	"code.gitea.io/gitea/modules/password"
 | 
			
		||||
	api "code.gitea.io/gitea/modules/structs"
 | 
			
		||||
	"code.gitea.io/gitea/routers/api/v1/convert"
 | 
			
		||||
	"code.gitea.io/gitea/routers/api/v1/user"
 | 
			
		||||
@@ -73,7 +76,11 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
 | 
			
		||||
	if ctx.Written() {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !password.IsComplexEnough(form.Password) {
 | 
			
		||||
		err := errors.New("PasswordComplexity")
 | 
			
		||||
		ctx.Error(400, "PasswordComplexity", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if err := models.CreateUser(u); err != nil {
 | 
			
		||||
		if models.IsErrUserAlreadyExist(err) ||
 | 
			
		||||
			models.IsErrEmailAlreadyUsed(err) ||
 | 
			
		||||
@@ -131,6 +138,11 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(form.Password) > 0 {
 | 
			
		||||
		if !password.IsComplexEnough(form.Password) {
 | 
			
		||||
			err := errors.New("PasswordComplexity")
 | 
			
		||||
			ctx.Error(400, "PasswordComplexity", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		var err error
 | 
			
		||||
		if u.Salt, err = models.GetUserSalt(); err != nil {
 | 
			
		||||
			ctx.Error(500, "UpdateUser", err)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user