From 1b462fac46eaf387f47a274a9f6bd9b46cd19981 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 14 Jul 2016 15:16:34 +0200 Subject: Move username/email validation functions to muser Signed-off-by: Florian Pritz --- application/models/muser.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'application/models/muser.php') diff --git a/application/models/muser.php b/application/models/muser.php index f2b961d89..4ec821f4d 100644 --- a/application/models/muser.php +++ b/application/models/muser.php @@ -134,6 +134,31 @@ class Muser extends CI_Model { return $this->session->userdata('username'); } + /* + * Check if a given username is valid. + * + * Valid usernames contain only lowercase characters and numbers. They are + * also <= 32 characters in length. + * + * @return boolean + */ + public function valid_username($username) + { + return strlen($username) <= 32 && preg_match("/^[a-z0-9]+$/", $username); + } + + /** + * Check if a given email is valid. Only perform minimal checking since + * verifying emails is very very difficuly. + * + * @return boolean + */ + public function valid_email($email) + { + $this->load->helper("email"); + return valid_email($email); + } + function get_userid() { if (!$this->logged_in()) { -- cgit v1.2.3-24-g4f1b