Skip to content

Commit

Permalink
Merge pull request #16 from billmn/develop
Browse files Browse the repository at this point in the history
Added check if Username already exists on user creation
  • Loading branch information
Jelmer Schreuder committed Jul 29, 2011
2 parents 7fdce72 + f07a91a commit 54aab6d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion classes/auth/login/simpleauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ public function create_user($username, $password, $email, $group = 1, Array $pro
return false;
}

$same_users = \DB::select()
->where('username', '=', $username)
->or_where('email', '=', $email)
->from(\Config::get('simpleauth.table_name'))
->execute();

if($same_users->count() > 0)
{
if (in_array(strtolower($username), array_map('strtolower', $same_users->current())))
{
throw new \SimpleUserUpdateException('Username already exists');
}

if (in_array(strtolower($email), array_map('strtolower', $same_users->current())))
{
throw new \SimpleUserUpdateException('Email address already exists');
}
}

return false;

if( $same_users->count() > 0 )
{
throw new \SimpleUserCreateException('Username already exists');
}

$user = array(
'username' => (string) $username,
'password' => $this->hash_password((string) $password),
Expand Down Expand Up @@ -423,4 +449,4 @@ public function guest_login()
}
}

// end of file simpleauth.php
// end of file simpleauth.php

0 comments on commit 54aab6d

Please sign in to comment.