コード例 #1
0
ファイル: auth.go プロジェクト: natefinch/claymud
// queryUser asks the user to create a new username and password.
func queryUser(rw io.ReadWriter) (user, pwd string, err error) {
	user, err = util.QueryVerify(rw, []byte("Username: "******"", fmt.Errorf("error checking for existence of username: %s", err)
			}
			if !exists {
				return "", nil
			}
			return "That username already exists, please choose another.", nil
		})
	if err != nil {
		return "", "", err
	}
	pwd, err = util.QueryVerify(rw, []byte("Password: "******"The maximum length for a password is 1024 characters.", nil
			}
			return "", nil
		})
	if err != nil {
		return "", "", err
	}
	return user, pwd, nil
}
コード例 #2
0
ファイル: auth.go プロジェクト: natefinch/claymud
// createUser creates the user if it does not exist.  If it does exist,
// createUser will return ErrExists.
func createUser(username, pw string, ip net.Addr) (user *world.User, err error) {
	// do the expensive hash outside the critical section!!
	hash, err := bcrypt.GenerateFromPassword([]byte(pw), bcryptCost)
	if err != nil {
		return nil, err
	}

	exists, err := db.UserExists(username)
	if err != nil {
		return nil, err
	}
	if exists {
		return nil, ErrExists
	}

	if err := db.SaveUser(username, ip, hash); err != nil {
		return nil, err
	}
	user = &world.User{
		Username: username,
	}
	return user, nil
}