<?php

include("./ayanasu_fosh/fosh.inc");
function getPASSWD_HASH1($AYANASU_ID)
{
  global $AYANASU_fosh;
  if ($AYANASU_ID==$AYANASU_fosh['AYANASU_ID']) return $AYANASU_fosh['HASH1'];
  else return FALSE;
}

if (isset($_POST['AYANASU_ID']) && isset($_POST['AYANASU_PASS']) && isset($_POST['KOEY_salt']) && isset($_POST['KOEY_uniq'])) {

    $strcheck=TRUE;
    if (!preg_match('/\A([0-9A-Fa-f])+\Z/',$_POST['AYANASU_PASS'])) $strcheck=FALSE;
    if (!preg_match('/\A([0-9A-Za-z_ ])+\Z/',$_POST['KOEY_salt'])) $strcheck=FALSE;
    if (!preg_match('/\A([0-9A-Fa-f])+\Z/',$_POST['KOEY_uniq'])) $strcheck=FALSE;
    $userID = htmlspecialchars($_POST['AYANASU_ID'], ENT_QUOTES);
    if (!preg_match('/\A([0-9A-Za-z_ ])+\Z/',AYANASU_ID)) $strcheck=FALSE;
    if ($strcheck===TRUE) {

    $HASH1=getPASSWD_HASH1($AYANASU_ID);

      if ($HASH1!==FALSE) {
      $HASH2= hash('sha256', $_POST['KOEY_uniq'] . ":" . $HASH1);
      if($_POST['AYANASU_PASS']===$HASH2) {
      session_start();
      $_SESSION["USERID"] = $_POST["KOEY_uniq"];
      header("Location: AYANASU_control.php");
      $message="感謝いたします！";
      }else{$message = "認証内容を正しくご入力くださいませ。<br>";}
      }
  }
}else{$message = "";}

?>
<html lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="./control/style.css" type="text/css">
<link rel="stylesheet" href="./control/style_768.css" type="text/css">
<link rel="stylesheet" href="./foundation-icons/foundation-icons.css" />
<script src="./ayanasu_fosh/sha256.js"></script>
<script type="text/javascript">
<!--
function SubmitIdPass() {
  var tmp1=document.frm_login.AYANASU_ID.value+":"+document.frm_login.KOEY_salt.value+":"+document.frm_login.AYANASU_PASS.value;
  var shaObj1=new jsSHA(tmp1, "ASCII");
  var sha256digest1 = shaObj1.getHash("SHA-256", "HEX");
  var tmp2=document.frm_login.KOEY_uniq.value+":"+sha256digest1;
  var shaObj2=new jsSHA(tmp2, "ASCII");
  var sha256digest2 = shaObj2.getHash("SHA-256", "HEX");
  document.frm_login.AYANASU_PASS.value=sha256digest2;
  document.frm_login.submit();
}
// -->
</script>
<title>AYANASU Login</title>
</head>
<body>

<div id="login_logo">
<a href="http://www.koey.net/" target="_blank"><img src="img_ctrl/ayanasu_logo_50.png"> AYANASU glob</a>
</div>

<div id="login">

<form name="frm_login" method="post">
ユーザーID：<input type="text" name="AYANASU_ID">
<br><br>
パスワード：<input type="password" name="AYANASU_PASS">
<br>
<input type="hidden" name="KOEY_salt" value="<?php echo $KOEY_salt; ?>">
<input type="hidden" name="KOEY_uniq" value="<?php echo uniqid(); ?>">
<br>
<input type="button" onclick="SubmitIdPass();" name="" value="ログイン" >
</form>
<?php print $message;?>
</div>

<div id="login_link">
<a href="./index.php"><div class="fi-home"> 貴方のステキなホームページはこちらですよ</div></a>
<br>
<a href="http://www.koey.net/index.php?name=help_002" target="_blank"><div class="fi-lightbulb">ログイン情報をお忘れでしょうか？</div></a>
<br><br>
</div>

</body>
</html>
