CI Authentication via CLI - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: CI Authentication via CLI (/showthread.php?tid=63135) |
CI Authentication via CLI - jLinux - 09-29-2015 Im in the middle of writing an application that can be accessed and used via various methods, such as HTTP, Ajax, cURL, wget, and im hoping to also make it accessible when executed via the command line using php. I was wondering if anyone has written an application that runs via CLI, that also requires authentication? I get that if they are executing it this way, chances are they already have access to the accounts, but the passwords would be encrypted anyways. Thanks! RE: CI Authentication via CLI - skunkbad - 10-03-2015 I would start here: http://php.net/manual/en/book.readline.php RE: CI Authentication via CLI - jLinux - 10-03-2015 (10-03-2015, 02:37 PM)skunkbad Wrote: I would start here: Hm, I've never heard of that before, and ill look into it, but does anyone have a way that doesnt require installing more modules? (trying to keep it as easy as possible for those who download the app) Edit: actually, the script I found via google just had a module I dont have, looks like readline is there, ill try it out! RE: CI Authentication via CLI - jLinux - 10-03-2015 Weird, not all the readline functions are compiled into the library I have apparently... (OSX) RE: CI Authentication via CLI - ivantcholakov - 10-03-2015 I have a piece of code that shows how CLI authentication could be made. https://github.com/ivantcholakov/starter-public-edition-4/blob/v4.0.78/platform/common/models/Current_user.php You can write something similar/simpler or to try to upgrade a ready solution using the idea. RE: CI Authentication via CLI - jLinux - 10-03-2015 (10-03-2015, 09:24 PM)ivantcholakov Wrote: I have a piece of code that shows how CLI authentication could be made. How exactly is authentication done on the CLI using that? RE: CI Authentication via CLI - ivantcholakov - 10-04-2015 Within the CLI script you can call Code: $success = $this->current_user->login_by_id(2); // 2 is the user id, it can be taken from a configuration file. Code: $success = $this->current_user->login($username, $password); // The same user, username and password can be taken from a configuration file. login_by_id() is better for this purpose. Let us say you have a special user, that is to be logged through CLI: id: 2 username: robot password: $2F94934860394860348609645690 first_name: I last_name: Robot system_account: 1 // 0 means a normal account used by a human being. For system accounts like this, logging-in from web should be disabled. And then your cron-tasks can use this account for logging-in. If some task modifies some data, then the system account id will be stored within the corresponding "created_by" and "modified_by" fields (if you implement such tracking). You will know then which data has been changed by a normal user and which data - automatically, by a cron-task. |