title: Authentication if the user is Logged in or Not?
body: <p>I am new in using the .htaccess file. 
  I am learning to create my very first dashboard and can't even know how to protect it from hackers or any other threat. I don't know how to authenticate if the user is actually logged in or he/she redirected only using the search bar to redirect to the main page.
  Now, I learned that the HTACCESS file can authenticate if the user is actually logged in, and/or not even he/she tries to redirect using the search bar, it will show the 404 error page.</p>
  
  <p>But now, I have seen this sample .htaccess file.
  <a href="http://www.htaccess-guide.com/how-to-use-htaccess/" rel="nofollow noreferrer">http://www.htaccess-guide.com/how-to-use-htaccess/</a></p>
  
  <p>and can't substitute the right path of every HTML.</p>
  
  <p>any help would be much appreciated. </p>
  
  <p>This is the htaccess file</p>
  
  <pre><code>AuthName "Member's Area Name"
  AuthUserFile /path/to/password/file/.htpasswd
  AuthType Basic
  require valid-user
  ErrorDocument 401 /error_pages/401.html
  AddHandler server-parsed .html
  </code></pre>
  
  <p>Thank you and Regards,</p>
  
  <blockquote>
    <p><strong>EDIT</strong></p>
  </blockquote>
  
  <p>As I have said Above, I am new in web development And trying to develop my very first dashboard. Currently, I want to authenticate if the user is actually logged in or not. For now, I have this code that will check the sessionStorage if there is more than 1 value. If not, It will redirect to the login page of the dashboard.</p>
  
  <pre><code>$(document).ready(function () {
      AESDecrypt();
  })
  
  function AESDecrypt() {
      if (sessionStorage.length &lt;= 1) {
          window.sessionStorage.clear();
          window.location.href = "login.html";
      } else {
          var userInfo = sessionStorage.getItem("AppHunt");
          var decryptUser = CryptoJS.AES.decrypt(userInfo, AESuserDataEncryptions.AESPASSWORD);
          var strUserFullName = decryptUser.toString(CryptoJS.enc.Utf8);
          var strUserFullName = strUserFullName.toString();
          validateUSERAccount(strUserFullName);
      }
  }
  
  function validateUSERAccount(decryptedUser) {
      var value = "{'user':" + decryptedUser
                  + "}";
      $.ajax({
          type: 'POST',
          url: '../WebService/wsIndex.asmx/ValidateUserAccount',
          dataType: 'json',
          data: value,
          contentType: 'application/json; charset=utf-8',
          success: function (response) {
              var cells = eval("(" + response.d + ")");
              if (cells.length &lt;= 0) {
                  window.location.href = "login.html";
              }
  
          },
          error: function (error) {
              console.log(error);
          }
      });
  }
  </code></pre>
  
  <p>There is no Problem in the code below, But I want to know if there is a more effective solution to redirect the user in the login page if he/she does not logged in to any account. </p>