1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\System\Utils;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2019, Afterlogic Corp.
14: */
15: class Validate
16: {
17: /**
18: * @param string $sFuncName
19: * @return string
20: */
21: public static function GetError($sFuncName)
22: {
23: switch ($sFuncName) {
24: case 'Port':
25: return 'Required valid port.';
26: case 'IsEmpty':
27: return 'Required fields cannot be empty.';
28: }
29:
30: return 'Error';
31: }
32:
33: /**
34: * @param mixed $mValue
35: * @return bool
36: */
37: public static function IsValidLogin($mValue)
38: {
39: return preg_match('/^[a-zA-Z0-9@\-_\.]+$/', $mValue);
40: }
41:
42: /**
43: * @param mixed $mValue
44: * @return bool
45: */
46: public static function IsEmpty($mValue)
47: {
48: return !is_string($mValue) || 0 === strlen($mValue);
49: }
50:
51: /**
52: * @param mixed $mValue
53: * @return bool
54: */
55: public static function Port($mValue)
56: {
57: $bResult = false;
58: if (0 < strlen((string) $mValue) && is_numeric($mValue)) {
59: $iPort = (int) $mValue;
60: if (0 < $iPort && $iPort < 65355) {
61: $bResult = true;
62: }
63: }
64: return $bResult;
65: }
66:
67: /**
68: * @param mixed $mValue
69: * @return bool
70: */
71: public static function IsValidPassword($mValue)
72: {
73: $bResult = true;
74: $oSettings =& \Aurora\System\Api::GetSettings();
75: $iPasswordMinLength = $oSettings->PasswordMinLength;
76: $bPasswordMustBeComplex = $oSettings->PasswordMustBeComplex;
77:
78: if (strlen($mValue) < $iPasswordMinLength) {
79: $bResult = false;
80: } elseif ($bPasswordMustBeComplex && (!preg_match('([0-9])', $mValue) || !preg_match('([!,%,&,@,#,$,^,*,?,_,~])', $mValue))) {
81: $bResult = false;
82: }
83:
84: return $bResult;
85: }
86: }
87: