35 function Check_HomeCU_Status(&$p_dbh, &$p_hb_env) {
39 $p_hb_env[
'cu'] = substr(filter_input(INPUT_GET,
'cu', FILTER_SANITIZE_STRING, array(
'flags' => (FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH))), 0, 12);
40 if ($p_hb_env[
'cu'] ==
'' && in_array(basename($_SERVER[
'SCRIPT_NAME']), array(
'OFXRequest.prg',
'hcuAppFeed.prg'))) {
41 $p_hb_env[
'cu'] = substr(filter_input(INPUT_POST,
'ORG', FILTER_SANITIZE_STRING, array(
'flags' => (FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH))), 0, 12);
42 $p_hb_env[
'no_cookies'] =
true;
44 if ($p_hb_env[
'homebanking_status'] !=
"O") {
45 $p_dbh = db_pconnect($p_hb_env[
'SYSENV'][
'db']);
54 $sql=
"SELECT cookie_ver, loginscript, offlinestat, offlineblurb, trmemomaxlen, min_chlng_qst, 55 livewait, trim(lastupdate), flagset, flagset2, flagset3, histdays, trmemomaxlen, 56 coalesce(retrylimit,5), coalesce(gracelimit,5), orgname, pname, rt, tz, livebatch 58 WHERE cu = '{$p_hb_env['cu']}'";
59 $sth = db_query($sql, $p_dbh);
61 if (db_num_rows($sth) > 0) {
62 list ($cver, $loginscript, $offline, $offlinemsg, $trmemomaxlen, $min_chlng_qst, $livewait,
63 $lastupdate, $flagset, $flagset2, $flagset3, $histdays, $trmemomaxlen,
64 $failedremain, $forceremain, $orgname, $pname, $rt, $tz, $livebatch) = db_fetch_array($sth,0);
66 $p_hb_env[
'cver'] = ($cver ==
'F' ?
'F' :
'L');
68 $p_hb_env[
'offline'] = (trim($offline) ==
'' ?
'N' : trim($offline));
69 $p_hb_env[
'offlinemsg'] = $offlinemsg;
70 $p_hb_env[
'trmemomaxlen'] = intval($trmemomaxlen);
71 $p_hb_env[
'cu_chgqst_count'] = intval($min_chlng_qst);
73 $p_hb_env[
'livewait'] = (is_null($livewait) ?
"300" : $livewait);
74 $p_hb_env[
'lastupdate'] = (trim($lastupdate)==
"" ?
"Unknown" : urlencode(trim($lastupdate)));
75 $p_hb_env[
'flagset'] = (is_null($flagset) ? 0 : $flagset);
76 $p_hb_env[
'flagset2'] = (is_null($flagset2) ? 0 : $flagset2);
77 $p_hb_env[
'flagset3'] = (is_null($flagset3) ? 0 : $flagset3);
78 $p_hb_env[
'histdays'] = (is_null($histdays) ? 0 : $histdays);
79 $p_hb_env[
'trmemomaxlen'] = (is_null($trmemomaxlen) ? 0 : $trmemomaxlen);
80 $p_hb_env[
'failedremain'] = $failedremain;
81 $p_hb_env[
'forceremain'] = $forceremain;
82 $p_hb_env[
'orgname'] = trim($orgname);
83 $p_hb_env[
'pname'] = trim($pname);
84 $p_hb_env[
'rt'] = trim($rt);
85 $p_hb_env[
'chome'] = strtolower($p_hb_env[
'cu']);
86 $p_hb_env[
'live'] = (trim($livebatch) ==
'L' ? 1 : 0);
87 $p_hb_env[
'tz'] = trim($tz) ==
"" ?
"US/Mountain" : ((strpos($tz,
"/") === false ) ?
"US/" . trim($tz) : trim($tz));
92 $p_hb_env[
'cver'] =
"F";
93 $p_hb_env[
'loginscript'] =
"cuauth";
94 $p_hb_env[
'offline'] =
"Y";
95 $p_hb_env[
'offlinemsg'] =
"We are currently working on the system.";
102 $p_hb_env[
'cver'] =
"F";
103 $p_hb_env[
'loginscript'] =
"cuauth";
104 $p_hb_env[
'offline'] =
"Y";
105 $p_hb_env[
'offlinemsg'] =
"We are currently working on the system.";
110 $p_hb_env[
'Flang'] =
'';
111 if ( HCU_array_key_exists(
"no_cookies", $p_hb_env ) ) {
112 $p_hb_env[
'Flang'] =
'en_US';
117 $cookieName = $p_hb_env[
'cu'] .
'_lang';
118 if (HCU_array_key_exists( $cookieName, $_COOKIE)) {
119 $p_hb_env[
'Flang'] = $_COOKIE[$cookieName];
126 $p_hb_env[
'currentscript'] = basename($_SERVER[
'SCRIPT_NAME']);
128 $p_hb_env[
'remoteIp'] = filter_input(INPUT_SERVER,
'REMOTE_ADDR', FILTER_SANITIZE_STRING);
138 return ($offline ==
'N' ? FALSE : TRUE);
164 function LoadCUAdmin( $pDbh, $pCU, &$pEnv ) {
169 if ($pEnv[
'homebanking_status'] !=
"O") {
175 # Check $pCU before using it, since it is not escaped in the sql below 176 # ctype_alnum ensures not empty / null, and contains only letters / digits 177 if ( $pDbh && ctype_alnum($pCU) ) {
180 $sql=
"SELECT cu, cookie_ver, loginscript, offlinestat, offlineblurb, trmemomaxlen, min_chlng_qst, 181 livewait, trim(lastupdate), flagset, flagset2, flagset3, histdays, trmemomaxlen, 182 coalesce(retrylimit,5), coalesce(gracelimit,5), orgname, pname, rt, tz, livebatch 184 WHERE cu = '{$pCU}'";
185 $sth = db_query($sql, $pDbh);
187 if (db_num_rows($sth) > 0) {
188 list ($cu, $cver, $loginscript, $offline, $offlinemsg, $trmemomaxlen, $min_chlng_qst, $livewait,
189 $lastupdate, $flagset, $flagset2, $flagset3, $histdays, $trmemomaxlen,
190 $failedremain, $forceremain, $orgname, $pname, $rt, $tz, $livebatch) = db_fetch_array($sth,0);
192 $pEnv[
'cver'] = ($cver ==
'F' ?
'F' :
'L');
194 $pEnv[
'offline'] = (trim($offline) ==
'' ?
'N' : trim($offline));
195 $pEnv[
'offlinemsg'] = $offlinemsg;
196 $pEnv[
'trmemomaxlen'] = intval($trmemomaxlen);
197 $pEnv[
'cu_chgqst_count'] = intval($min_chlng_qst);
199 $pEnv[
'livewait'] = ((is_null($livewait) || $livewait ==
"0") ?
"300" : $livewait);
200 $pEnv[
'lastupdate'] = (trim($lastupdate)==
"" ?
"Unknown" : urlencode(trim($lastupdate)));
201 $pEnv[
'flagset'] = (is_null($flagset) ? 0 : $flagset);
202 $pEnv[
'flagset2'] = (is_null($flagset2) ? 0 : $flagset2);
203 $pEnv[
'flagset3'] = (is_null($flagset3) ? 0 : $flagset3);
204 $pEnv[
'histdays'] = (is_null($histdays) ? 0 : $histdays);
205 $pEnv[
'trmemomaxlen'] = (is_null($trmemomaxlen) ? 0 : $trmemomaxlen);
206 $pEnv[
'failedremain'] = $failedremain;
207 $pEnv[
'forceremain'] = $forceremain;
208 $pEnv[
'orgname'] = trim($orgname);
209 $pEnv[
'pname'] = trim($pname);
210 $pEnv[
'rt'] = trim($rt);
211 $pEnv[
'chome'] = trim(strtolower($cu));
212 $pEnv[
'live'] = (trim($livebatch) ==
'L' ? 1 : 0);
213 $pEnv[
'tz'] = trim($tz) ==
"" ?
"US/Mountain" : ((strpos($tz,
"/") === false ) ?
"US/" . trim($tz) : trim($tz));
215 $isOffline = !( $pEnv[
'offline'] ==
"N" );
226 $pEnv[
'loginscript'] =
"cuauth";
227 $pEnv[
'offline'] =
"Y";
228 $pEnv[
"offlinemsg"] = HCU_array_key_exists(
"offlinemsg", $pEnv) ? trim($pEnv[
"offlinemsg"]) :
"";
229 $pEnv[
'offlinemsg'] = $pEnv[
"offlinemsg"] ==
"" ?
"We are currently working on the system." : $pEnv[
"offlinemsg"];
268 function Check_Member_Settings($p_dbh, $p_hb_env, $p_mc) {
270 $retAry = Array(
"code" =>
"000",
"severity" =>
"SUCCESS",
"errors" => Array());
296 $p_hb_env[
'allowReadonly'] =
false;
298 if (!hcu_checkOffline($p_dbh, $p_hb_env)) {
307 $aryMfaQuest = GetChallengeQuestions(
'CURRENT', $p_dbh, $p_hb_env, $p_mc, $p_hb_env[
'Cn']);
313 if (($p_hb_env[
'cver'] ==
"F") && ($aryMfaQuest[
'mfacount'] == 0 && intval($p_hb_env[
'cu_chgqst_count']) > 0) && !($p_hb_env[
'Fset3'] & GetFlagsetValue(
'CU3_MFA_AUTHCODE'))) {
317 $retAry[
'code'] = ($retAry[
'code'] ==
'000' ?
"010" : $retAry[
'code']);
318 $retAry[
'severity'] =
"ERROR";
319 $retAry[
'errors'][] = $p_mc->msg(
"Need challenge questions");
321 if (($p_hb_env[
'cver'] ==
"F") && ($p_hb_env[
'Ffreset'])) {
323 if (intval(HCU_array_key_value(
'sC', $p_hb_env)) !=
'2' || $p_hb_env[
'Ffremain'] == 0) {
325 $retAry[
'code'] = ($retAry[
'code'] ==
'000' ?
"011" : $retAry[
'code']);
326 $retAry[
'severity'] =
"ERROR";
327 $retAry[
'errors'][] = $p_mc->msg(
"Need challenge questions");
335 if ($p_hb_env[
'Ffchg'] ==
'Y') {
336 if (intval(HCU_array_key_value(
'sC', $p_hb_env)) !=
'2') {
337 $retAry[
'code'] = ($retAry[
'code'] ==
'000' ?
"012" : $retAry[
'code']);
338 $retAry[
'severity'] =
"ERROR";
339 $retAry[
'errors'][] = $p_mc->msg(
"Password flagged reset");
344 if (($p_hb_env[
'Fmsg_tx'] & GetMsgTxValue(
'MSGTX_FORCE_EM')) !== 0) {
345 if (intval(HCU_array_key_value(
'sC', $p_hb_env)) !=
'2') {
346 $retAry[
'code'] = ($retAry[
'code'] ==
'000' ?
"013" : $retAry[
'code']);
347 $retAry[
'severity'] =
"ERROR";
348 $retAry[
'errors'][] = $p_mc->msg(
"Bad Email Flag");
354 if ( ($p_hb_env[
'Fset2'] & $GLOBALS[
'CU2_ALIAS_REQ']) == $GLOBALS[
'CU2_ALIAS_REQ']) {
364 $mbrInfo = GetUserInfo($p_dbh, $p_hb_env, $p_mc, Array(
"user_id" => $p_hb_env[
'Uid'],
"cu" => $p_hb_env[
'Cu']));
366 if ($mbrInfo[
'status'][
'code'] ==
'000') {
367 if (!Check_Member_UseAlias($mbrInfo[
'data'][
'cuusers_user_name'])) {
368 if (intval(HCU_array_key_value(
'sC', $p_hb_env)) !=
'2') {
369 $retAry[
'code'] = ($retAry[
'code'] ==
'000' ?
"014" : $retAry[
'code']);
370 $retAry[
'severity'] =
"ERROR";
371 $retAry[
'errors'][] = $p_mc->msg(
"Alias required");
389 function Check_Member_UseAlias($p_username) {
390 return preg_match(
"/\D/",$p_username);
409 function Check_Member_Credentials (&$hb_env, $ticket) {
410 $retVal = Array(
"result"=>
"",
"resdesc"=>
"");
414 $retVal[
'result'] = 1;
417 $returnArray = CheckSessionTicket($hb_env, $ticket);
420 if ( !is_array( $returnArray[
'result'] ) ) {
425 if (preg_match(
'/Cn=(.+?)\b/', $ticket, $matches)) {
426 $username = $matches[1];
430 $logTicketCheckGate =
new CreditUnionGate(CreditUnionGate::LOG_TICKET_CHECK_FEATURE, $config);
431 if ($logTicketCheckGate->WillPass($hb_env[
'cu'], [
'username' => $username])) {
432 $hb_env[
'SYSENV'][
'logger']->info(
"[CheckCredentialsFailure] ticket=$ticket; resdesc={$returnArray['resdesc']}");
435 $retVal[
'result'] = 0;
436 $retVal[
"resdesc"] = $returnArray[
"resdesc"];
441 syslog(LOG_ERR, $retVal[
'resdesc']);
447 $allowENV=array(
'Ctime'=>
'Time',
'Ce'=>
'Expires',
'Cu'=>
'CU',
448 'Cn'=>
'Login Member',
'Uid'=>
'Login User ID',
'Clw'=>
'Wait',
'Clu'=>
'Last Update',
449 'Fplog'=>
'Prior Login',
'Fflog'=>
'Last Failed',
450 'Ffchg'=>
'Force Change',
'Ffreset'=>
'Force Reset',
'Ffremain'=>
'Fails Remaining',
451 'Fmsg_tx'=>
'Msg Status',
'Fset'=>
'Flagset 1',
'Fset2'=>
'Flagset 2',
452 'Fset3'=>
'Flagset 3',
'Ca' =>
"Admin user (user hub member account list)",
453 'Fhdays'=>
'History Days',
'Ml'=>
'Email Address',
'platform'=>
'Client platform',
454 'sC'=>
'Security Challenge Status',
'testmenu'=>
'Show Test Menu',
'sid'=>
'Session Id');
457 # $tarr is built (above) from ticket cookie; then 458 # values from $tarr which have keys present in $allowENV 459 # are used to add/update values in $p_hb_env 460 $hb_env = array_replace( $hb_env, array_intersect_key( $returnArray[
"result"], $allowENV ) );
465 $hb_env[
'lastupdate'] = $hb_env[
'Clu'];
477 function CheckSessionTicket( $pHBEnv, $sessionStr ) {
479 $retVal = Array(
"result" => array(),
"resdesc" =>
"" );
481 if ( empty($sessionStr) ) {
483 throw new Exception(
"Ticket not found {$pHBEnv['cu']}" );
487 parse_str( $sessionStr, $tarr );
490 if ( $tarr[
'Ce'] < $now ) {
492 throw new Exception(
"{$tarr['Cu']}:{$tarr['Uid']} Ticket Expired {$tarr['Ce']} < $now" );
495 if ( $pHBEnv[
'cu'] !=
"" &&
496 $pHBEnv[
'cu'] != $tarr[
'Cu'] ) {
498 throw new Exception(
"{$tarr['Cu']}:{$tarr['Uid']} Ticket Switch cu from {$tarr['Cu']} to {$pHBEnv['cu']}" );
504 if (is_null($tarr[
'Ch']) || is_null($tarr[
'Cn']) || is_null($tarr[
'Uid']) ||
505 is_null($tarr[
'Ctime']) || is_null($tarr[
'Ce']) ||
506 is_null($tarr[
'Cu']) || is_null($tarr[
'Clw']) ||
507 is_null($tarr[
'Clu']) || is_null($tarr[
'Fplog']) || is_null($tarr[
'Fflog']) ||
508 is_null($tarr[
'Ffchg']) || is_null($tarr[
'Ffremain']) ||
509 is_null($tarr[
'Fmsg_tx']) || is_null($tarr[
'Fset']) ||
510 is_null($tarr[
'Fset2']) || is_null($tarr[
'Fhdays']) || is_null($tarr[
"Ca"]) ||
511 is_null($tarr[
'Fset3']) || is_null($tarr[
'Ml']) || is_null($tarr[
"platform"]) || is_null($tarr[
"sid"])) {
513 throw new Exception(
"{$tarr['Cu']}:{$tarr['Cn']} Partial Ticket" );
516 $secret = $pHBEnv[
'secret'];
520 if ($tarr[
'Ch'] != MD5($secret .
524 $tarr[
'Ctime'], $tarr[
'Ce'], $tarr[
'Cu'], $tarr[
'Cn'], $tarr[
'Uid'],
525 $tarr[
'Clw'], urlencode(trim($tarr[
'Clu'])), urlencode(trim($tarr[
'Fplog'])), urlencode(trim($tarr[
'Fflog'])),
526 $tarr[
'Ffchg'], $tarr[
'Ffreset'],
527 $tarr[
'Ffremain'], $tarr[
'Fmsg_tx'], $tarr[
'Fset'],
528 $tarr[
'Fset2'], $tarr[
'Fset3'], $tarr[
'Fhdays'],
529 urlencode($tarr[
'Ml']), trim($tarr[
"Ca"]), trim($tarr[
"platform"]), $tarr[
"sid"]
533 throw new Exception(
"{$tarr['Cu']}:{$tarr['Uid']} Ticket Hash Mismatch" );
536 $retVal[
"result"] = $tarr;
537 }
catch (Exception $err) {
538 $retVal[
"result"] =
false;
539 $retVal[
"resdesc"] = $err->getMessage();
543 if ( !empty($_COOKIE[
'Ticket']) ) {
547 apache_note(
"user_name",
"{$tarr['Cu']}:{$tarr['Uid']}");
559 function GetReturnAddress ($p_hb_env, $p_bolforce_setcookie = 0) {
561 $return_address = $p_hb_env[
'loginpath'] .
"/{$p_hb_env['defaultScript']}?{$p_hb_env['cuquery']}";
563 return $return_address;
566 function GetUserbyName($p_dbh, $cu, $username) {
567 $return_ary = array();
569 $sqluser =
"SELECT cuuser.user_id as user_id, trim(cuuser.user_name) as user_name, trim(cuuser.passwd) as passwd, 570 forcechange as fchange, coalesce(forceremain,0) as fremain, failedremain, pwchange as pchange, 571 trim(email) as email, confidence, cuuser.group_id as cuuser_group_id, 572 lastlogin as llog, failedlogin as flog, coalesce(msg_tx,0) as msg_tx, userflags & " . GetUserFlagsValue(
'MEM_FORCE_RESET') .
"::int4 as freset, 573 userflags, coalesce(challenge_quest_id,0) as savecqid, 574 coalesce(cuadmin.flagset,0) as flagset, coalesce(cuadmin.flagset2,0) as flagset2, coalesce(cuadmin.flagset3,0) as flagset3, 575 cuadmin.livewait, trim(cuadmin.lastupdate) as lastupdate, cuadmin.min_chlng_qst as min_chlng_qst, 576 cuadmin.pname, coalesce(histdays,0) as fhdays, coalesce(gracelimit,0) as grace, trmemomaxlen, mfaquest, primary_account, trim(cuadmin.cu) as cu 578 FROM {$cu}user as cuuser 579 JOIN cuadmin on cuadmin.cu = '" . prep_save($cu) .
"' 580 WHERE lower(cuuser.user_name) = '" . prep_save(strtolower($username)) .
"' ";
582 $mbr_sth = db_query($sqluser, $p_dbh);
583 if (db_num_rows($mbr_sth) == 1) {
584 $return_ary = db_fetch_assoc($mbr_sth,0);
585 $return_ary[
'rowfound'] = 1;
586 $mbrMfaQuest = HCU_MFADecode(HCU_JsonDecode($return_ary[
'mfaquest']));
587 $return_ary[
'savecqid'] = $mbrMfaQuest[
'challenge'];
588 $return_ary[
'chcount'] = $mbrMfaQuest[
'mfacount'];
589 $return_ary[
'authcode'] = $mbrMfaQuest[
'authcode'];
590 $return_ary[
'authexpires'] = $mbrMfaQuest[
'authexpires'];
591 $return_ary[
'mfadate'] = $mbrMfaQuest[
'mfadate'];
594 if ($return_ary[
'fchange'] ==
'Y') {
595 $FORCEUPDATE += 1; #password
598 if (($return_ary[
'msg_tx'] & GetMsgTxValue(
'MSGTX_FORCE_EM')) || $return_ary[
'email'] ==
'') {
599 $FORCEUPDATE += 2; # email
601 if (intval($return_ary[
'flagset3'] & GetFlagsetValue(
'CU3_MFA_AUTHCODE')) == 0 &&
602 ( $return_ary[
'freset'] == GetUserFlagsValue(
'MEM_FORCE_RESET') || $return_ary[
'chcount'] < $return_ary[
'min_chlng_qst'])
604 $FORCEUPDATE += 4; #challenge questions
606 if (($return_ary[
'flagset2'] & GetFlagsetValue(
'CU2_ALIAS_REQ')) && !Check_Member_UseAlias($return_ary[
'user_name'])) {
613 $return_ary[
'forceupdate'] = $FORCEUPDATE;
616 if ($return_ary[
'failedremain'] <= 0 || ( ($return_ary[
'forceupdate'] & 29) > 0 && $return_ary[
'fremain'] <= 0 )) {
618 $return_ary[
'lockedacct'] = 1;
620 $return_ary[
'lockedacct'] = 0;
624 $return_ary[
'rowfound'] = 0;
699 function BankingVerifyCredentials($p_dbh, $p_mode, &$p_hb_env, $p_mc, $pLoginType =
"MBL") {
706 $retVal = Array(
"status" =>
"100",
"dispmsg" => Array(),
"nextstep" =>
"StepMember");
732 $username = trim($p_hb_env[
'username']);
733 $cu = trim($p_hb_env[
'cu']);
735 if (hcuCheckUsername($username)) {
737 $userrec = GetUserbyName($p_dbh, $cu, $username);
738 if ( $userrec[
'rowfound'] != 1) {
760 $retVal[
'status'] =
"030";
761 $retVal[
'dispmsg'][] =
'';
762 $retVal[
'nextstep'] =
'StepPass';
764 if (strlen($p_hb_env[
'password']) > 0) {
771 $retVal[
'status'] =
"140";
772 $retVal[
'dispmsg'][] = $p_mc->msg(
"Invalid Login Password");
773 $retVal[
'nextstep'] =
"StepMember";
781 $p_hb_env[
'confidence'] = $userrec[
'confidence'];
784 if ($userrec[
'lockedacct']) {
785 apache_note(
"user_name",
"{$cu}:_Fl_{$userrec['user_name']}/{$username}"); #
this will capture same value twice - use UID or Primary Acct instead?
787 $userMemReset = $userrec[
'flagset'] & GetFlagsetValue(
'CU_MEMRESET');
788 $userForceReset = $userrec[
'userflags'] & GetUserFlagsValue(
'MEM_FORCE_RESET');
789 $userFailedRemain = $userrec[
'failedremain'] >= 0;
791 if ($userMemReset && !$userForceReset && $userFailedRemain) {
792 if ($pLoginType ==
"MBL") {
793 $resetlink = $p_hb_env[
'loginpath'] .
"/resetpwd.prg?cu={$p_hb_env['cu']}&Flang={$p_hb_env['Flang']}";
794 } elseif ($pLoginType ==
"DSK") {
795 $resetlink = $p_hb_env[
'loginpath'] .
"/hcuResetPwd.prg?cu={$p_hb_env['cu']}";
799 $retVal[
'status'] =
"112";
800 $retVal[
'dispmsg'][] = $p_mc->combo_msg(
'Account is Locked Reset', 0,
'#link#',
"$resetlink");
802 $retVal[
'nextstep'] =
"StepMember";
804 $retVal[
'status'] =
"112";
805 $retVal[
'dispmsg'][] = $p_mc->msg(
'Account is Locked');
806 $retVal[
'nextstep'] =
"StepMember";
813 if (isValidDeviceCookie($cu, $userrec) || IsValidMammothDeviceCookie($p_hb_env, $cu, $userrec)) {
820 $p_hb_env[
'username'] = $username;
822 $retVal[
'status'] =
"030";
823 $retVal[
'dispmsg'][] =
'';
824 $retVal[
'nextstep'] =
"StepPass";
828 $p_hb_env[
'email'] = $userrec[
'email'];
834 $p_hb_env[
'username'] = $username;
836 $retVal[
'status'] =
"010";
837 $retVal[
'dispmsg'][] =
"";
838 $retVal[
'nextstep'] =
"StepEmail";
843 if ($retVal[
'nextstep'] ==
'StepEmail' && trim($p_hb_env[
'email']) !=
'') {
847 $email = trim($p_hb_env[
'email']);
848 if (!isValidEmail($email, $userrec)) {
851 apache_note(
"user_name",
"{$cu}:_Fm_{$userrec['user_name']}/{$username}");
853 $sth = UpdateMemberFailedLogin($p_dbh, $p_hb_env[
'cu'], $userrec[
'user_name'], $GLOBALS[
'MEM_LOGIN_FAILED_EMAIL']);
854 TrackUserLogin($p_dbh, array(
'Cu' => $cu,
'Uid' => $userrec[
'user_id'],
'user_name' => $userrec[
'user_name']), $pLoginType, $GLOBALS[
'MEM_LOGIN_FAILED_EMAIL'], $_SERVER[
'REMOTE_ADDR'], array(
'UA' => $_SERVER[
'HTTP_USER_AGENT']));
856 $retVal[
'status'] =
"120";
858 $retVal[
'dispmsg'] = Array();
859 $retVal[
'dispmsg'][] = $p_mc->msg(
'Invalid Login Email');
860 $retVal[
'nextstep'] =
"StepMember";
862 $retVal[
'status'] =
"020";
863 $retVal[
'dispmsg'][] =
"";
866 if (intval($p_hb_env[
'flagset3'] & $GLOBALS[
'CU3_MFA_AUTHCODE'])) {
867 $retVal[
'nextstep'] =
"StepSecureAccess";
869 $retVal[
'nextstep'] =
"StepChallenge";
872 } elseif ($retVal[
'nextstep'] ==
'StepEmail' && trim($p_hb_env[
'email']) ==
'') {
874 $retVal[
'dispmsg'][] = $p_mc->msg(
'Additional Authentication');
882 if ($retVal[
'nextstep'] ==
"StepChallenge") {
883 if ($userrec[
'freset'] == 0 && $userrec[
'chcount'] > 0) {
884 if (HCU_array_key_exists(
"challengeresponses", $p_hb_env) && count($p_hb_env[
'challengeresponses']) > 0) {
885 if (isValidChallenge($userrec, $p_hb_env[
'challengeresponses'])) {
886 $retVal[
'status'] =
"030";
887 $retVal[
'dispmsg'][] =
'';
888 $retVal[
'nextstep'] =
"StepPass";
890 apache_note(
"user_name",
"{$cu}:_Fq_{$userrec['user_name']}/{$username}");
891 $sth = UpdateMemberFailedLogin($p_dbh, $cu, $userrec[
'user_name'], $GLOBALS[
'MEM_LOGIN_FAILED_QST']);
892 TrackUserLogin($p_dbh, array(
'Cu' => $cu,
'Uid' => $userrec[
'user_id'],
'user_name' => $userrec[
'user_name']), $pLoginType, $GLOBALS[
'MEM_LOGIN_FAILED_QST'], $_SERVER[
'REMOTE_ADDR'], array(
'UA' => $_SERVER[
'HTTP_USER_AGENT']));
894 $retVal[
'status'] =
"130";
895 $retVal[
'dispmsg'][] = $p_mc->msg(
'Invalid Login Challenge');
896 $retVal[
'nextstep'] =
"StepMember";
899 } elseif ($userrec[
'chcount'] == 0 || $userrec[
'freset'] == GetUserFlagsValue(
'MEM_FORCE_RESET')) {
902 $retVal[
'nextstep'] =
"StepPass";
906 if ($retVal[
'nextstep'] ==
"StepSecureAccess") {
907 if ($userrec[
'freset'] == GetUserFlagsValue(
'MEM_FORCE_RESET')) {
911 $retVal[
'nextstep'] =
"StepPass";
913 if (!empty($p_hb_env[
'authcode'])) {
914 if (isValidAuthcode($userrec, $p_hb_env[
'authcode'])) {
915 $retVal[
'status'] =
"030";
916 $retVal[
'dispmsg'][] =
'';
917 $retVal[
'nextstep'] =
"StepPass";
919 apache_note(
"user_name",
"{$cu}:_Fq_{$userrec['user_name']}/{$username}");
920 $sth = UpdateMemberFailedLogin($p_dbh, $cu, $userrec[
'user_name'], $GLOBALS[
'MEM_LOGIN_FAILED_SAC']);
921 TrackUserLogin($p_dbh, array(
'Cu' => $cu,
'Uid' => $userrec[
'user_id'],
'user_name' => $userrec[
'user_name']), $pLoginType, $GLOBALS[
'MEM_LOGIN_FAILED_SAC'], $_SERVER[
'REMOTE_ADDR'], array(
'UA' => $_SERVER[
'HTTP_USER_AGENT']));
923 $retVal[
'status'] =
"135";
924 $retVal[
'dispmsg'][] = $p_mc->msg(
'Invalid Login Challenge');
925 $retVal[
'nextstep'] =
"StepMember";
933 if (strlen($p_hb_env[
'password']) > 0 && $retVal[
'nextstep'] ==
'StepPass') {
946 # if (isValidPass($userrec,$p_hb_env['password'])) { 947 $minLenPassword = (strlen(trim($p_hb_env[
'password'])) < 4 ? false :
true);
949 if ($minLenPassword && $userrec[
'rowfound'] > 0) {
951 $mbrMfaQuest = HCU_MFADecode(HCU_JsonDecode($userrec[
'mfaquest']));
953 # why are we matching email here? 954 if ((strtolower(trim($userrec[
'email'])) == strtolower(trim($p_hb_env[
'email'])) || trim($userrec[
'email']) ==
'') && password_verify($p_hb_env[
'password'], $userrec[
'passwd'])) {
958 $freset = (is_null($userrec[
'freset']) ? 0 : $userrec[
'freset']);
961 $p_hb_env[
'Uid'] = $userrec[
'user_id'];
962 $p_hb_env[
'Cn'] = $userrec[
'user_name'];
963 $p_hb_env[
'Ce'] = time() + $p_hb_env[
'SYSENV'][
'ticket'][
'expires'];
964 $p_hb_env[
'Clw'] = $userrec[
'livewait'];
965 $p_hb_env[
'Clu'] = (empty($userrec[
'lastupdate']) ? $p_mc->msg(
"Unknown") : urlencode(trim($userrec[
'lastupdate'])));
966 $p_hb_env[
'lastupdate'] = (empty($userrec[
'lastupdate']) ?
"Unknown" : urlencode(trim($userrec[
'lastupdate'])));
967 $p_hb_env[
'Fplog'] = (empty($userrec[
'llog']) ? $p_mc->msg(
"None") : urlencode(trim($userrec[
'llog'])));
968 $p_hb_env[
'Fflog'] = (empty($userrec[
'flog']) ? $p_mc->msg(
"None") : urlencode(trim($userrec[
'flog'])));
969 $p_hb_env[
'Ffchg'] = (is_null($userrec[
'fchange']) ?
'N' : $userrec[
'fchange']);
970 $p_hb_env[
'Ffremain'] = (is_null($userrec[
'fremain']) || $userrec[
'fremain'] == 0 ? $userrec[
'grace'] : $userrec[
'fremain']);
971 $p_hb_env[
'Fmsg_tx'] = $userrec[
'msg_tx'];
972 $p_hb_env[
'Fset'] = $userrec[
'flagset'];
973 $p_hb_env[
'Fset2'] = $userrec[
'flagset2'];
974 $p_hb_env[
'Fset3'] = $userrec[
'flagset3'];
975 $p_hb_env[
'Fhdays'] = $userrec[
'fhdays'];
976 $p_hb_env[
'Ml'] = $userrec[
'email'];
977 $p_hb_env[
'Ffreset'] = $userrec[
'freset'];
980 $p_hb_env[
'savepass'] = $userrec[
'passwd'];
981 $p_hb_env[
'savemail'] = $userrec[
'email'];
984 $p_hb_env[
"sid"] = strval(time());
1005 $updateEmail = (trim($userrec[
'email']) ==
'' && trim($p_hb_env[
'email']) >
'');
1007 if ($upd_mbr_force || $updateEmail) {
1008 $updTable = array(
'user' => array(
1010 "_action" =>
"update",
1011 "user_id" => $p_hb_env[
'Uid']
1015 if ($upd_mbr_force) {
1018 $valueUserFlag = ($userrec[
'userflags'] ==
'' ? $GLOBALS[
'MEM_FORCE_RESET'] : ($userrec[
'userflags'] | $GLOBALS[
'MEM_FORCE_RESET']));
1019 $updTable[
'user'][0][
'userflags'] = $valueUserFlag;
1020 $updTable[
'user'][0][
'forceremain'] = $userrec[
'fremain'];
1021 $freset |= $GLOBALS[
'MEM_FORCE_RESET'];
1024 $updTable[
'user'][0][
'email'] = trim($p_hb_env[
'email']);
1027 $updateResults = DataUserTableUpdate($p_dbh, $p_hb_env, $p_mc, $updTable, $userrec[
'user_id'],
'U_UPD', $pLoginType, $p_hb_env[
'currentscript'],
'U', ($upd_mbr_force ?
"Force Mbr Update / " :
"") . ($updateEmail ?
"Set Email" :
""), $userrec[
'user_name'], $p_hb_env[
'email'], $p_hb_env[
'remoteIp'], !$updateEmail);
1031 $p_hb_env[
'Ffreset'] = $userrec[
'freset'];
1036 apache_note(
"user_name",
"{$cu}:{$username}");
1038 $baseCookie = BuildBaseSessionTicket( $p_hb_env );
1039 $mycookie =
"Ctime=$now&Cn={$userrec['user_name']}&Uid={$userrec['user_id']}&Ml=" . urlencode($userrec[
'email']) .
"&Ca=";
1042 if (intval(HCU_array_key_value(
'testmenu', $p_hb_env[
'HCUPOST'])) == 1) {
1043 $mycookie .=
"&testmenu=1";
1047 SetTicket($p_hb_env, $baseCookie, $mycookie);
1073 $tempReadonly = $p_hb_env[
'allowReadonly'];
1074 $p_hb_env[
'allowReadonly'] =
false;
1076 if (!hcu_checkOffline($p_dbh, $p_hb_env)) {
1080 $funcPchange = date(
'Y-m-d', mktime(0, 0, 0, date(
"m"), date(
"d") + 1, date(
"Y")));
1082 $funcFchange = ($userrec[
'freset'] == 2 ?
'Y' : $p_hb_env[
'Ffchg']);
1083 $funcPchange = (is_null($userrec[
'pchange']) ? date(
'Ymd') : $userrec[
'pchange']);
1085 $p_hb_env[
'allowReadonly'] = $tempReadonly;
1090 $mbrMfaQuest[
'challenge'] = 0;
1091 $mbrMfaQuest[
'authcode']=
'';
1092 $mbrMfaQuest[
'authexpires']=
'';
1096 $sth = UpdateMemberLoginTrack($p_dbh, $p_hb_env[
'cu'], $username, $funcFchange, $funcPchange, $pLoginType, $mbrMfaQuest);
1097 TrackUserLogin($p_dbh, array(
'Cu' => $p_hb_env[
'cu'],
'Uid' => $userrec[
'user_id'],
'user_name' => $username), $pLoginType, 0, $_SERVER[
'REMOTE_ADDR'], array(
'UA' => $_SERVER[
'HTTP_USER_AGENT']));
1100 if ($p_hb_env[
'HCUPOST'][
'chksecure'] ==
'Y') {
1101 SetDeviceCookie($p_hb_env, $userrec);
1105 $retVal[
'status'] =
"000";
1106 $retVal[
'dispmsg'][] =
"";
1107 $retVal[
'nextstep'] =
"StepNone";
1111 apache_note(
"user_name",
"{$cu}:_Fp_{$username}");
1112 $sth = UpdateMemberFailedLogin($p_dbh, $cu, $userrec[
'user_name'], $GLOBALS[
'MEM_LOGIN_FAILED_PWD']);
1113 TrackUserLogin($p_dbh, array(
'Cu' => $cu,
'Uid' => $userrec[
'user_id'],
'user_name' => $userrec[
'user_name']), $pLoginType, $GLOBALS[
'MEM_LOGIN_FAILED_PWD'], $_SERVER[
'REMOTE_ADDR'], array(
'UA' => $_SERVER[
'HTTP_USER_AGENT']));
1114 $retVal[
'status'] =
"140";
1115 $retVal[
'dispmsg'][] = $p_mc->msg(
"Invalid Login Password");
1116 $retVal[
'nextstep'] =
"StepMember";
1120 $logFlag = $minLenPassword ?
"Fn" :
"Fp";
1121 $logUID = $minLenPassword ? 0 : $userrec[
'user_id'];
1122 # need a valid code for invalid user name? 1123 $logCode = $minLenPassword ? $GLOBALS[
'MEM_LOGIN_FAILED_PWD'] : 0;
1124 apache_note(
"user_name",
"{$cu}:_{$logFlag}_{$username}");
1125 $sth = UpdateMemberFailedLogin($p_dbh, $cu, $username, $logCode);
1126 TrackUserLogin($p_dbh, array(
'Cu' => $cu,
'uid' => $logUID,
'user_name' => $username), $pLoginType, $logCode, $_SERVER[
'REMOTE_ADDR'], array(
'UA' => $_SERVER[
'HTTP_USER_AGENT']));
1128 $retVal[
'status'] =
"140";
1129 $retVal[
'dispmsg'][] = $p_mc->msg(
"Invalid Login Password");
1130 $retVal[
'nextstep'] =
"StepMember";
1138 $retVal[
'status'] =
"030";
1139 $retVal[
'dispmsg'][] =
'';
1140 $retVal[
'nextstep'] =
'StepPass';
1142 if (strlen($p_hb_env[
'password']) > 0) {
1149 $retVal[
'status'] =
"140";
1150 $retVal[
'dispmsg'][] = $p_mc->msg(
"Invalid Login Password");
1151 $retVal[
'nextstep'] =
"StepMember";
1167 function isValidEmail($email, $userrec) {
1168 if ((trim($userrec[
'email']) >
'' && strtolower(trim($userrec[
'email'])) == strtolower(trim($email))) ||
1169 (trim($userrec[
'email']) ==
'' && validateEmail($email))) {
1172 $return_val =
false;
1176 function activateWithCorePin($userrec, $p_hb_env) {
1177 $insflag = ($userrec[
'rowfound'] == 0 ? 1 : 0);
1188 list ($status, $asofdate, $reason) = fetch_user($cu, $username, $p_hb_env[
'password'], $insflag);
1189 if ($status ==
"100" || $status ==
"101") {
1191 $userrec = GetUserbyName($p_dbh, $cu, $username);
1193 } elseif ($status ==
"200" || $status ==
"201" || $status ==
"202") {
1194 $retVal[
'status'] =
"140";
1195 $retVal[
'dispmsg'][] = $p_mc->msg(
"CU System Unavailable");
1196 $retVal[
'nextstep'] =
"StepMember";
1199 $retVal[
'status'] =
"140";
1200 $retVal[
'nextstep'] =
"StepMember";
1213 function isValidChallenge($userrec, $challengeresponses) {
1216 $aryMfaQuest = HCU_JsonDecode($userrec[
'mfaquest']);
1217 $mbrMfaQuest = HCU_MFADecode($aryMfaQuest);
1218 $savecqid = $mbrMfaQuest[
'challenge'];
1219 $chcount = $mbrMfaQuest[
'mfacount'];
1227 if (count($challengeresponses) > 0) {
1243 $aryMfaAnswers = $aryMfaQuest[
'answers'];
1244 if (($userrec[
'flagset2'] & $GLOBALS[
'CU2_RANDOM_CHAL']) == $GLOBALS[
'CU2_RANDOM_CHAL'] && $mbrMfaQuest[
'challenge'] > 0) {
1246 $mfaAnswerIdx = Array($mbrMfaQuest[
'challenge']);
1249 $mfaAnswerIdx = array_keys($aryMfaAnswers);
1253 foreach (array_intersect_key($aryMfaAnswers, array_flip($mfaAnswerIdx)) as $qid => $qanswer) {
1254 $response =
"qid$qid";
1255 if (strtolower(trim($qanswer)) != strtolower(trim($challengeresponses[$response]))) {
1273 function isValidAuthcode($userrec, $authcode) {
1276 $aryMfaQuest = HCU_JsonDecode($userrec[
'mfaquest']);
1277 $mbrMfaQuest = HCU_MFADecode($aryMfaQuest);
1280 if ( $mbrMfaQuest[
'authexpires'] > time() && trim($mbrMfaQuest[
'authcode']) >
'' &&
1281 strtolower($authcode) == strtolower($mbrMfaQuest[
'authcode'])
1299 function isValidDeviceCookie($cu, $userrec) {
1302 $mfaMode = (intval($userrec[
'flagset3'] & GetFlagsetValue(
'CU3_MFA_AUTHCODE')));
1304 $mfaDate = HCU_array_key_value(
"mfadate", $userrec);
1306 $cookieParams = array (
"cu" => $cu,
1307 "user_name" => $userrec[
'user_name'],
1308 "saved_pass" => $userrec[
'passwd'],
1309 "saved_email" => $userrec[
'email'],
1310 "saved_confidence" => $userrec[
'confidence'],
1311 "mfa_mode" => $mfaMode,
1312 "mfa_date" => $mfaDate,
1313 "persists_time" => 0
1316 $cookieInfo = CreateDeviceCookie( $cookieParams);
1318 if (!empty($_COOKIE[$cookieInfo[
"name"]]) && ($cookieInfo[
"content"] == $_COOKIE[$cookieInfo[
"name"]]) && ($userrec[
'freset'] != GetUserFlagsValue(
'MEM_FORCE_RESET'))) {
1321 $return_val =
false;
1341 function IsValidMammothDeviceCookie( $pHBEnv, $pCu, $pUserRec ) {
1345 if ( ($pHBEnv[
"flagset3"] & GetFlagsetValue(
"CU3_ALLOW_COOKIE_MIGRATION")) > 0 &&
1346 $pUserRec[
'freset'] != GetUserFlagsValue(
'MEM_FORCE_RESET') ) {
1348 $sql =
"SELECT DISTINCT ua.accountnumber 1350 INNER JOIN {$pCu}useraccounts ua on ua.user_id = u.user_id 1351 WHERE u.user_name ilike '{$pHBEnv["username
"]}'";
1353 $rs = db_query( $sql, $pHBEnv[
"dbh"] );
1356 while ( $aRow = db_fetch_array( $rs, $row++ ) ) {
1357 $thisAccount = $aRow[
"accountnumber"];
1358 $mammothCookieName = Return2FactorName( $pHBEnv[
'cu'], $pHBEnv[
'2factorkey'], trim($thisAccount) );
1360 if ( isset( $_COOKIE[$mammothCookieName] ) ) {
1362 $mammothCookieContent = sha1( trim($pUserRec[
"passwd"]) . trim($pUserRec[
"email"]) . trim($pUserRec[
"confidence"]) );
1364 $retVal = $mammothCookieContent == $_COOKIE[$mammothCookieName];
1369 $pHBEnv[
"Cn"] = $pUserRec[
'user_name'];
1370 $pHBEnv[
"Fset3"] = $pUserRec[
'flagset3'];
1371 $pHBEnv[
"savepass"] = trim( $pUserRec[
"passwd"] );
1372 $pHBEnv[
"savemail"] = trim( $pUserRec[
"email"] );
1375 $inThePast = time() - 3600 * 24;
1376 HCU_setcookie_env( $pHBEnv[
'SYSENV'], $mammothCookieName,
"", $inThePast );
1379 SetDeviceCookie( $pHBEnv, $pUserRec);
1410 function CreateDeviceCookie( $pCookieParams) {
1411 $cookieName = Return2FactorName($pCookieParams[
"cu"], Get2FactorKeyString(), trim($pCookieParams[
"user_name"]));
1413 $cookieContent = hash_hmac(
'sha384',GetDeviceCookieContentString(),trim($pCookieParams[
"saved_pass"]) . trim(strtolower($pCookieParams[
"saved_email"])) . trim(strtolower($pCookieParams[
"saved_confidence"])) . $pCookieParams[
"mfa_mode"] . $pCookieParams[
"mfa_date"]);
1415 $expire = time() + $pCookieParams[
"persists_time"];
1417 return array(
"name" => $cookieName,
"content" => $cookieContent,
"expire" => $expire);
1430 function SetDeviceCookie($p_hb_env, $pUserRec) {
1434 if (
sizeof($_COOKIE) > 6
1435 && !preg_match(
"/^199.184.207/",$_SERVER[
'REMOTE_ADDR'])
1436 && !preg_match(
"/^192.168/",$_SERVER[
'REMOTE_ADDR'])) {
1438 $emsg =
"{$_SERVER['REMOTE_ADDR']} {$p_hb_env['cu']}:{$p_hb_env['Cn']} " . date(
'Y-m-d H:i:s') .
" " .
sizeof($_COOKIE) .
" Cookies";
1439 $p_hb_env[
'SYSENV'][
'logger']->warning($emsg);
1446 if (
sizeof($_COOKIE) > 23) {
1448 $persists = ($now - 3600);
1449 foreach ($_COOKIE as $cookiename => $cookiecontent) {
1450 if (!preg_match(
"/^(Tx_mURI|Ticket|webconnect)/",$cookiename)) {
1451 HCU_setcookie_env($p_hb_env[
'SYSENV'], $cookiename,
"", $persists);
1457 $mfaMode = (intval($p_hb_env[
'Fset3'] & GetFlagsetValue(
'CU3_MFA_AUTHCODE')));
1460 $mfaDate = HCU_array_key_value(
"mfadate", $pUserRec);
1462 $cookieParams = array (
"cu" => $p_hb_env[
"cu"],
1463 "user_name" => $p_hb_env[
"Cn"],
1464 "saved_pass" => $p_hb_env[
"savepass"],
1465 "saved_email" => $p_hb_env[
'savemail'],
1466 "saved_confidence" => $p_hb_env[
'confidence'],
1467 "mfa_mode" => $mfaMode,
1468 "mfa_date" => $mfaDate,
1469 "persists_time" => $p_hb_env[
'SYSENV'][
'ticket'][
'persists']
1472 $cookieInfo = CreateDeviceCookie( $cookieParams);
1475 HCU_setcookie_env($p_hb_env[
'SYSENV'], $cookieInfo[
"name"], $cookieInfo[
"content"], $cookieInfo[
"expire"]);
1498 function TrackUserLogin($p_dbh, $p_hb_env, $pLoginType, $status, $p_ipaddr, $p_meta) {
1506 if (!empty($p_hb_env[
'Uid'])) {
1507 $Cu = $p_hb_env[
'Cu'];
1508 $user_id = (empty($p_hb_env[
'Uid']) ? 0 : $p_hb_env[
'Uid']);
1509 $user_name = prep_save($p_hb_env[
'user_name'], 50);
1511 $callback =
function(&$item, $key) {
1512 $item = utf8_encode($item);
1514 array_walk($p_meta, $callback);
1516 $meta = prep_save(json_encode($p_meta));
1518 $sql =
"insert into {$Cu}userlogins (user_id, user_name, login_dt, hcucode, status, remote_ip, metadata) 1519 values ('$user_id', E'{$user_name}', CURRENT_TIMESTAMP, '{$pLoginType}', {$status}, '{$p_ipaddr}', E'{$meta}')";
1520 $sth = db_query($sql, $p_dbh);
1538 function Return2FactorName($p_cu, $p_key, $p_username) {
1540 return sha1(trim($p_cu) . $p_key . trim($p_username));
1545 function mobile_formatnumber($p_nbr, $p_show_separator =
true) {
1547 $inc_comma = ($p_show_separator ?
",":
"");
1548 if (is_numeric($p_nbr)) {
1549 return number_format($p_nbr, 2,
".", $inc_comma);
1554 function mobile_displayhtml($text,$charset=
'ISO-8859-1') {
1555 return htmlspecialchars(trim($text),ENT_QUOTES,$charset,
false);
1557 function mobile_formatdate($p_date) {
1564 if (trim($p_date) !=
"N/A") {
1565 if (($timestamp = strtotime($p_date)) !==
false) {
1566 $retVal = date(
"m/d/y", $timestamp);
1573 function mobile_formatdate_ipay($p_date) {
1576 $retVal = substr($p_date, 5, 2) .
"/" . substr($p_date, 8, 2) .
"/" . substr($p_date, 2, 2);
1591 function Get_PwdSpecialCharacters() {
1592 return "!,@,#,$,%,^,&,*,?,_,~,-,(,)";
1609 function check_alias_available($p_dbh, $p_hb_env, $p_useralias) {
1611 $sql =
"SELECT count(*) 1612 FROM {$p_hb_env['Cu']}user 1614 (lower(user_name) = '" . strtolower(prep_save($p_useralias, 50)) .
"' 1615 AND user_id <> '{$p_hb_env['Uid']}') ";
1616 $uniq_rs = db_query($sql, $p_dbh);
1617 list($uniq_cnt) = db_fetch_array($uniq_rs, 0);
1619 $uniq_cnt = ($uniq_cnt == 0 ? 0 : 1);
1622 return ($uniq_cnt == 0 ?
true :
false);
1637 function Get_AccountHPRDetails($p_dbh, $p_hb_env, $p_mc, $p_acct_key) {
1638 $retDetails = Array(
"holds" => Array(),
"pending" => Array(),
"requests" => Array());
1641 $AcctHolds_ary = Get_HoldDetails($p_dbh, $p_hb_env, $p_acct_key);
1642 if ($AcctHolds_ary[
'status'][
'code'] ==
'000') {
1643 if (HCU_array_key_exists( $p_acct_key, $AcctHolds_ary )) {
1645 $retDetails[
'holds'] = HCU_array_key_value( $p_acct_key, $AcctHolds_ary );
1650 $AcctPend_ary = Get_PendDetails($p_dbh, $p_hb_env, $p_acct_key);
1652 if ($AcctPend_ary[
'status'][
'code'] ==
'000') {
1653 if (HCU_array_key_exists( $p_acct_key, $AcctPend_ary )) {
1655 $retDetails[
'pending'] = HCU_array_key_value( $p_acct_key, $AcctPend_ary );
1660 $AcctReq_ary = Get_ReqDetails($p_dbh, $p_hb_env, $p_acct_key);
1662 if ($AcctReq_ary[
'status'][
'code'] ==
'000') {
1665 if (HCU_array_key_exists(
'acctlist', $AcctReq_ary)) {
1666 if (count($AcctReq_ary[
'acctlist'][$p_acct_key]) > 0) {
1667 foreach ($AcctReq_ary[
'acctlist'][$p_acct_key] as $request_details) {
1669 $retDetails[
'requests'][] = Array (
1670 "amount" => $request_details[
'amount'],
1671 "postdate" => HCU_array_key_value(
'date', $request_details),
1672 "description" => $request_details[
'txdesc'],
1673 "traceno" => $request_details[
'id']
1692 function Return_Random4Challenge($p_hb_env) {
1695 if ($_COOKIE[
'PWDCHG']) {
1696 $cookieval = $_COOKIE[
'PWDCHG'];
1698 $cookie_arr = Array();
1699 parse_str($cookieval, $cookie_arr);
1701 if ($cookie_arr[
'p3'] == MD5($p_hb_env[
'secret'] . MD5(join (
':', array($cookie_arr[
'p1'], $cookie_arr[
'p2']))))) {
1703 if ($cookie_arr[
'p2'] > time()) {
1704 $retVal = intval($cookie_arr[
'p1']);
1714 function hcuCheckUsername($username) {
1719 $username >
'' && !(preg_match(
"/[\\\`,\"\s;]/", $username))
1738 function generateAuthcode($length = 6, $ttl = 2400) {
1739 $length = intval($length);
1740 # valid range 6 to 10 digits, default 6 digits 1741 $length = ($length < 6 || $length >10 ? 6 : $length);
1742 $ttl = intval($ttl);
1743 # valid range 15 minutes to 3 hours, default 40 minutes 1744 $ttl = ($ttl < 900 || $ttl > 10800 ? 2400 : $ttl);
1745 $result = substr(str_repeat(
'0',$length) . rand(0,pow(10,$length)),-$length,$length);
1746 return array(
'authcode' => $result,
'authexpires' => time() + $ttl);
1763 function setAuthcode ($p_dbh, $p_hb_env, $p_mc, &$userrec, $authcode, $authexpires) {
1779 $mbrMfa = HCU_MFADecode(HCU_JsonDecode($userrec[
'mfaquest']));
1780 $mbrMfa[
'authcode'] = $authcode;
1781 $mbrMfa[
'authexpires'] = $authexpires;
1783 $mbrSaveMfa = PrepareMfaQuestString($mbrMfa);
1785 $userrec[
'authcode'] = $authcode;
1786 $userrec[
'authexpires'] = $authexpires;
1787 $userrec[
'mfaquest'] = $mbrSaveMfa;
1790 $upd_list_array = serialize(Array(
"mfaquest" => $mbrSaveMfa));
1791 $upd_keys_array = serialize(Array(
"user_name" => $userrec[
'user_name']));
1792 $updateResponse = Update_MemberInfo($p_dbh, $p_hb_env, $p_mc, $upd_list_array, $upd_keys_array);
1794 if ($updateResponse[
'status'][
'code'] !=
'000') {
1803 function setAdminAuthcode ($dbh, $Cu, $Cn, $authcode) {
1812 $altIP = $_SERVER[
'REMOTE_ADDR'];
1813 $timeStamp = time();
1816 $saveUserConfirm = $authcode .
"|" . $altIP .
"|" . $timeStamp .
"|0";
1819 $sql =
"Update cuadminusers SET userconfirm = '$saveUserConfirm' WHERE cu = '$Cu' AND user_name = '$Cn'";
1820 $sth = db_query($sql,$dbh);
1843 function sendAuthcode ($dbh, $p_hb_env, $userrec, $retSendTo) {
1845 $unmasked = HCU_PayloadDecode($userrec[
'cu'], $retSendTo,
false);
1846 $retSendHow = $unmasked[0];
1847 $retSendTo = $unmasked[1];
1848 $MsgFromName = $p_hb_env[
'orgname']; # encoding / escaping needed? Handle empty?
1849 $MsgSubj = trim($p_hb_env[
'orgname']) .
" Authentication Request";
1852 $hcuAuth = $userrec[
'authcode'];
1853 $hcuExpires = $userrec[
'authexpires'];
1854 $timeExpire = round( ($userrec[
'authexpires'] - time()) / 60 );
1859 if ($retSendHow ==
'S') {
1861 $MsgBody =
"Code: $hcuAuth\n";
1862 $MsgBody .=
"Sent from {$p_hb_env['orgname']}\n";
1863 $MsgBody .=
"Secure Access Code expires in $timeExpire minutes.\n";
1868 $retSendTo = preg_replace(
'/^([\+]{0,1})(\d+)(\@.*)/',
'$2', $retSendTo);
1870 if ($p_hb_env[
'flagset3'] & GetFlagsetValue(
'CU3_LONGCODE_MFA')) {
1871 $retSendFrm = GetCuSMSFrom($dbh, $userrec[
'cu']);
1874 $msg_response = SendLongCodeSMS($GLOBALS[
'HOMECU_LONGCODE_API_KEY'], $GLOBALS[
'HOMECU_LONGCODE_URL'], $retSendFrm, $retSendTo, $MsgBody, $p_hb_env);
1877 $msg_response = SendAwsSMS($retSendTo, $p_hb_env[
'orgname'], $MsgBody,
true);
1880 } elseif ($retSendHow ==
'E') {
1882 $MsgBody =
"Code: $hcuAuth <br><br>";
1883 $MsgBody .=
"Sent from {$p_hb_env['orgname']}<br><br>";
1884 $MsgBody .=
"Secure Access Code expires in $timeExpire minutes.<br>";
1886 # send to the email address stored in the userrec 1888 $retSendFrm = GetCuEmailFrom($dbh, $userrec[
'cu']);
1890 $notify->header =
"Content-type: text/html";
1891 $notify->mailto = $retSendTo;
1892 $notify->mailfromname = $MsgFromName;
1893 $notify->mailfrom = $retSendFrm;
1894 $notify->subject = $MsgSubj;
1895 $notify->msgbody =
"$MsgBody";
1896 $notify->callingfunction = __FUNCTION__;
1897 $notify->file = __FILE__;
1898 $notify->cu = $userrec[
'cu'];
1901 $msg_response = TRUE;
1903 # error - invalid method 1904 $msg_response = FALSE;
1906 return $msg_response;
1909 function sendAdminAuthcode ($dbh, $Cu, $authResp, $retSendTo, $retSendHow) {
1912 $sql =
"SELECT orgname FROM cuadmin WHERE cu = '$Cu'";
1913 $sth = db_query( $sql, $dbh );
1914 $orgName = db_fetch_array( $sth, 0 )[0];
1916 $MsgFromName = $orgName;
1917 $MsgSubj = trim($orgName) .
" Authentication Request";
1920 $hcuAuth = $authResp[
'authcode'];
1921 $hcuExpires = $authResp[
'authexpires'];
1923 $timeExpire = round( ($authResp[
'authexpires'] - time()) / 60 );
1925 if ($retSendHow ==
'sms') {
1927 $MsgBody =
"Sent from {$orgName}\n\n";
1928 $MsgBody .=
"Secure Access Code expires in $timeExpire minutes.\n";
1929 $MsgBody .=
"Code: $hcuAuth";
1934 $retSendTo = preg_replace(
'/^([\+]{0,1})(\d+)(\@.*)/',
'$2', $retSendTo);
1937 $msg_response = SendAwsSMS($retSendTo, $orgName, $MsgBody,
true);
1939 } elseif ($retSendHow ==
'email') {
1941 $MsgBody =
"Sent from {$orgName}<br><br>";
1942 $MsgBody .=
"Secure Access Code expires in $timeExpire minutes.<br>";
1943 $MsgBody .=
"Code: $hcuAuth";
1945 # send to the email address stored in the userrec 1947 $retSendFrm = GetCuEmailFrom($dbh, $Cu);
1949 $notify->header =
"Content-type: text/html";
1950 $notify->mailto = $retSendTo;
1951 $notify->mailfromname = $MsgFromName;
1952 $notify->mailfrom = $retSendFrm;
1953 $notify->subject = $MsgSubj;
1954 $notify->msgbody =
"$MsgBody";
1955 $notify->callingfunction = __FUNCTION__;
1956 $notify->file = __FILE__;
1958 $notify->SendMail();
1959 $msg_response = TRUE;
1961 # error - invalid method 1962 $msg_response = FALSE;
1964 return $msg_response;
1981 function GetUserContacts($p_dbh, $p_hb_env, $userrec) {
1982 $retList = array(
'EMAIL' => array(),
'SMS' => array(),
'Found' => 0,
'GotIt' => 0);
1983 # load email from {cu}user record 1984 if (trim($userrec[
'email']) >
'' && validateEmail($userrec[
'email'])) {
1985 $key = HCU_PayloadEncode($p_hb_env[
'Cu'], array(
'E',trim($userrec[
'email'])),
false);
1986 $retList[
'EMAIL'][$key] = hcuMaskEmail(trim($userrec[
'email']));
1987 $retList[
'Found']++;
1989 # get phones from {cu}usercontact 1990 $sql =
"select uc.phones from {$p_hb_env['Cu']}usercontact as uc " 1991 .
"join {$p_hb_env['Cu']}user as cu_user on cu_user.contact = uc.contact_id " 1992 .
"where cu_user.user_id = " . intval($userrec[
'user_id']) .
";";
1993 $sth = db_query($sql, $p_dbh);
1994 if (db_num_rows($sth) == 1) {
1995 list($phones) = db_fetch_array($sth, 0);
1996 if ($phones !=
"" && $phones !=
"[]") {
1997 $phones = HCU_JsonDecode($phones);
1998 if (is_array($phones)) {
1999 foreach ($phones as $phtype=>$phnum) {
2004 if (is_array($phnum)) {
2006 for ($phIdx = 0; $phIdx < count($phnum); $phIdx++) {
2007 if ($phnum[$phIdx] !=
"" && hcuCheckPhone($phnum[$phIdx])) {
2008 $key = HCU_PayloadEncode($p_hb_env[
'Cu'], array(
'S',preg_replace(
'/\D/',
'', $phnum[$phIdx])),
false);
2009 $retList[
'SMS'][$key] = hcuMaskPhone($phnum[$phIdx]);
2010 $retList[
'Found']++;
2016 if ($phnum !=
"" && hcuCheckPhone($phnum)) {
2017 $key = HCU_PayloadEncode($p_hb_env[
'Cu'], array(
'S',preg_replace(
'/\D/',
'', $phnum)),
false);
2018 $retList[
'SMS'][$key] = hcuMaskPhone($phnum);
2019 $retList[
'Found']++;
2027 $aryMfaQuest = HCU_JsonDecode($userrec[
'mfaquest']);
2028 $mbrMfaQuest = HCU_MFADecode($aryMfaQuest);
2029 if ( $mbrMfaQuest[
'authexpires'] > (time() + 120) && trim($mbrMfaQuest[
'authcode']) >
'' ) {
2030 # if we have a code good for at least 2 more minutes, send the link 2031 $retList[
'GotIt'] =
true;
2045 function GetCuSMSFrom($dbh, $cu) {
2048 $sql =
"SELECT trim(email) FROM cuadmnotify 2049 WHERE cu = '$cu' and role = 'txtbanking' ";
2051 $sth = db_query($sql, $dbh);
2053 if (db_num_rows($sth) == 1) {
2054 list($sendfrom) = db_fetch_array($sth,0);
2057 $pattern =
'/^[+]{0,1}[0-9]{1,12}$/';
2058 if (empty($sendfrom) || !preg_match($pattern, $sendfrom)) {
2059 # invalid long code - get one from longcode round-robin 2060 $LONGCODE_ROUNDROBIN = array(
'+12672458136',
'+12082982149',
'+16017142198',
'+12082547302',
'+16017142199',
'+13306492200');
2062 $index = rand(0,
sizeof($LONGCODE_ROUNDROBIN) - 1);
2063 $sendfrom = $LONGCODE_ROUNDROBIN[$index];
2079 function GetCuEmailFrom($dbh, $cu) {
2080 $sql =
"SELECT trim(email) FROM cuadmnotify 2081 WHERE cu = '$cu' and role = 'securitychgfrom' ";
2083 $sth = db_query($sql, $dbh);
2084 if (db_num_rows($sth) == 1) {
2085 list($sendfrom) = db_fetch_array($sth,0);
2087 if (trim($sendfrom) ==
'' || !validateEmail($sendfrom) ) {
2088 # set default - also nag support@homecu.com to fix it? 2089 $sendfrom =
'noreply@homecu.com';
2102 function hcuCheckPhone($phone) {
2105 $phone = preg_replace(
'/\D/',
'', $phone);
2106 if (!is_numeric($phone) || $phone <= 0 || strlen($phone) != 10) {
2120 function hcuMaskPhone($phone) {
2121 # strip punctuation & apply mask 2122 $phone = preg_replace(
'/\D/',
'', $phone);
2124 $phone =
"xxx-xxx-" . substr($phone, 6);
2137 function hcuMaskEmail($email) {
2138 $marker = strpos($email,
'@');
2139 $retVal = substr_replace($email,str_repeat(
'.',$marker - 2), 1,$marker -2);