Easy way to check existence of a user in DB ? ( Newbie ) |
[eluser]Unknown[/eluser]
Hi, i'm a CodeIgniter newbie, i'm developing a simple authentication system. My validation controller (target of login form) looks like this: Code: $username = $this->input->post('username'); Is there a simple way to check the existence of that user in that table ? I did not found it on the user guide. Thanks in advance! (Sorry for my english)
[eluser]Dam1an[/eluser]
The easiest way is something like Code: $this->db->where('username', $username); You might need to chance variable names of the columns/table
[eluser]Slowcheetah[/eluser]
For the sake of security be sure to check this article; Handling Passwords In CodeIgniter
[eluser]Unknown[/eluser]
Dam1an, works like a charm! Thanks! Slowcheetah ok.. i will check that, thank you too
[eluser]tekhneek[/eluser]
I could be wrong, but wouldn't this achieve the same thing with less code? Code: $query = $this->db->get_where('users', array('username' => $username, 'password' => $password)); Code: function get_categories($featured = false) {
[eluser]Thorpe Obazee[/eluser]
[quote author="tekhneek" date="1242047286"]I could be wrong, but wouldn't this achieve the same thing with less code? [/quote] yes it does. [quote author="tekhneek" date="1242047286"] I've also noticed that using $this->db->where() is very handy in general, but obviously in situations where conditions are needed say for specific preset rows from a database like: etc.[/quote] That's the primary reason I use CI AR
[eluser]Dam1an[/eluser]
[quote author="tekhneek" date="1242047286"]I could be wrong, but wouldn't this achieve the same thing with less code? Code: $query = $this->db->get_where('users', array('username' => $username, 'password' => $password)); It would acheive the same with less code, but sometimes its better to be a bit more verbose and a little more clear I could probably do it all in 1 line of code if I wanted, but if it makes it complicated and difficult to understand, whats the point? (I know you're example isn't complicated per se, but I'm just making the point) |
Welcome Guest, Not a member yet? Register Sign In |