Move username/password validation to Storage class

This commit is contained in:
Alex Ling
2020-05-31 14:26:20 +00:00
parent 8bbbe650f1
commit b724b4d508
3 changed files with 24 additions and 32 deletions

View File

@@ -101,3 +101,22 @@ def redirect(env, path)
base = Config.current.base_url
env.redirect File.join base, path
end
def validate_username(username)
if username.size < 3
raise "Username should contain at least 3 characters"
end
if (username =~ /^[A-Za-z0-9_]+$/).nil?
raise "Username should contain alphanumeric characters " \
"and underscores only"
end
end
def validate_password(password)
if password.size < 6
raise "Password should contain at least 6 characters"
end
if (password =~ /^[[:ascii:]]+$/).nil?
raise "password should contain ASCII characters only"
end
end