title: CakePHP login without use of password, ONLY username
body: <p>After reading the post: <a href="https://stackoverflow.com/questions/5531410/how-to-cakephp-logging-in-without-password">logging without password</a></p>
  
  <p>I made a personal attempt:</p>
  
  <p>AppController:</p>
  
  <pre><code>function beforeFilter(){
  $this-&gt;Auth-&gt;loginError = "This message shows up when the wrong credentials are 
   used";       
   //$this-&gt;Auth-&gt;authError = "This error shows up with the user tries to access a part
   of the website that is protected."; 
      //$this-&gt;Auth-&gt;authError = "";
      $this-&gt;Auth-&gt;fields = array(
          'username' =&gt; 'username',
          'password' =&gt;   null 
     );
  </code></pre>
  
  <p>UsersController, inside <code>add()</code>:</p>
  
  <pre><code>// Save new user
     if ($this-&gt;User-&gt;save(array('username' =&gt; $this-&gt;request-&gt;data['User']['username'],
            'password' =&gt; $this-&gt;Auth-&gt;password(null),
            'name' =&gt; $this-&gt;request-&gt;data['User']['name'],
            'surname' =&gt; $this-&gt;request-&gt;data['User']['surname'],
            'chosenLayout' =&gt; $this-&gt;request-&gt;data['User']['chosenLayout'],
            'dateCreated' =&gt; $this-&gt;request-&gt;data['User']['dateCreated'],
            'dateModified' =&gt; $this-&gt;request-&gt;data['User']['dateModified'],
            'role_id' =&gt;$this-&gt;request-&gt;data['User']['role_id']        
     ))) {
  
      $this-&gt;Session-&gt;setFlash(__('message_success_user_added', 
      array($this-&gt;request-&gt;data['User']['username'])), 'default', array(), 'success');
      $this-&gt;redirect(array('action' =&gt; 'index'));
     } 
     else {
      // Validation error
   $this-&gt;Session-&gt;setFlash(__('message_fail_validation'), 'default', array(), 'fail');
     }
  </code></pre>
  
  <p>Then entered as admin and created some dummy users with null or random password.
  Checking the database encrypted passwords were all the same ( a hashed null string) which means the modification in <code>add()</code> function worked...</p>
  
  <p>Inside UsersController <code>login()</code>:</p>
  
  <pre><code>// Login User
  public function login() {
  
      // Check if the user is already logged in
      if ($this-&gt;Session-&gt;check('Auth.User.id')){ 
  
          // Redirect to login page
          $this-&gt;redirect($this-&gt;Auth-&gt;loginRedirect); 
      }
      else{
          // If the user is not logged in
  
          session_set_cookie_params(0); 
  
          // If the request is a POST request
          if ($this-&gt;request-&gt;is('post')) { 
              //get credentials
              $this-&gt;username = $this-&gt;request-&gt;data['User']['username'];
              $this-&gt;password = $this-&gt;request-&gt;data['User']['password'];
              $this-&gt;domain = $this-&gt;request-&gt;data['User']['domain'];
              //debug($this-&gt;username);
              debug($this-&gt;domain) ;
              //Check if username exists in local DB 
              //debug($this-&gt;User-&gt;findByUsername( $this-&gt;username ));
              if ($this-&gt;Auth-&gt;login(
                            array(
                             'username'=&gt; $this-&gt;username,
                              'password'=&gt; null)
  
                           )){
  
                  //   debug($this-&gt;Auth-&gt;login(array(
                    //          'username'=&gt; $this-&gt;username,
                      //        'password'=&gt; null
                          // )));
  
      // Successful login
      // Get all the user information and store in Session
      //debug($this-&gt;Auth);
  $this-&gt;User-&gt;id = $this-&gt;Auth-&gt;user('id');
      debug($this-&gt;User-&gt;id);
      debug($this-&gt;User);
  $this-&gt;User-&gt;contain(array('User', 'Role' =&gt; array('Ui', 'Action.name')));
      $this-&gt;Session-&gt;write('User', $this-&gt;User-&gt;read());
  
          $actions = array();
  foreach ($this-&gt;Session-&gt;read('User.Role.Action') as $key =&gt; $value){
  array_push($actions, $value['name']);
  }
  $this-&gt;Session-&gt;write('User.Role.Action', $actions);
  debug($actions);
  
  // Render different layout depending on user type
  
     if($this-&gt;Session-&gt;read('User.Role.Ui.name') == Configure::read('usertype.msp')){
  
     $this-&gt;Session-&gt;write('SessionValues.ui', Configure::read('usertype.msp'));
  $this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'PortStats', 'action' =&gt; 
     'index');
      }
  else if($this-&gt;Session-&gt;read('User.Role.Ui.name') == 
      Configure::read('usertype.tsc')){
  
      $this-&gt;Session-&gt;write('SessionValues.ui', Configure::read('usertype.tsc'));
  $this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'PortStats', 'action' =&gt; 
      'index');
                          }
  else if($this-&gt;Session-&gt;read('User.Role.Ui.name') == 
      Configure::read('usertype.superAdminUserType')){
  $this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'Uis', 'action' =&gt; 'index');
                          }
  
                      // Redirect to main login page
                  $this-&gt;redirect($this-&gt;Auth-&gt;loginRedirect);
  
                      }
                      else {
                      // Failed login user
                      session_destroy();
                      $this-&gt;Session-&gt;setFlash(__('Login failed: 
            access not granted'), 'default', array(), 'fail');
  
                      }
  
                  }
      }
  }
  </code></pre>
  
  <p>Then I try to login with my new users.I get the failed login message.
  Which means <code>$this-&gt;Auth-&gt;login</code> returns <code>false</code>. </p>
  
  <p>It must be as easy as that but something is going wrong.</p>
  
  <p>In the meantime my debug trace:</p>
  
  <blockquote>
    <p>Warning (2): Invalid argument supplied for foreach()
    [APP\Controller\UsersController.php, line 85]</p>
  </blockquote>