gxc
2019-11-07 045590bbb1efb46590b0dce0a5482cae284b33f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System;
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 密码错误信息提示控件
    /// </summary>
    public class PswErrorRowLayout : RowLayout
    {
        /// <summary>
        /// 现阶段是否错误
        /// </summary>
        public bool IsError = true;
        /// <summary>
        /// 密码长度不低于8位数
        /// </summary>
        private Button btnLength = null;
        /// <summary>
        /// 至少有一个大写字母
        /// </summary>
        private Button btnUpper = null;
        /// <summary>
        /// 至少有一个小写字母
        /// </summary>
        private Button btnLower = null;
        /// <summary>
        /// 至少有一个数字或符号
        /// </summary>
        private Button btnNumber = null;
        /// <summary>
        /// 其它
        /// </summary>
        private Button btnOther = null;
        /// <summary>
        /// 正确的图标
        /// </summary>
        private string rightIcon = "√ ";
        /// <summary>
        /// 错误的图标
        /// </summary>
        private string wrongIcon = "× ";
        /// <summary>
        /// 密码长度不低于8位数
        /// </summary>
        private string LengthMsg = Language.StringByID(R.MyInternationalizationString.PswLengthMsg);
        /// <summary>
        /// 至少有一个大写字母
        /// </summary>
        private string UpperMsg = Language.StringByID(R.MyInternationalizationString.PswLowerMsg);
        /// <summary>
        /// 至少有一个小写字母
        /// </summary>
        private string LowerMsg = Language.StringByID(R.MyInternationalizationString.PswLowerMsg);
        /// <summary>
        /// 至少有一个数字或符号
        /// </summary>
        private string NumberMsg = Language.StringByID(R.MyInternationalizationString.PswNumberMsg);
 
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public void Init(int width = 300, int height = 35)
        {
            //X轴偏移量
            //int XX = UserCenterResourse.XXLeft;
 
            //btnLength = UserCenterControls.MakeViewButton(width, height, true);
            //btnLength.X = XX;
            //btnLength.Y = Application.GetRealHeight(6);
            //btnLength.TextAlignment = TextAlignment.CenterLeft;
            //btnLength.TextColor = UserCenterColor.Current.Red;
            //btnLength.Text = wrongIcon + LengthMsg;
            //this.AddChidren(btnLength);
 
            //btnUpper = UserCenterControls.MakeViewButton(width, height, true);
            //btnUpper.X = XX;
            //btnUpper.Y = btnLength.Bottom + Application.GetRealHeight(6);
            //btnUpper.TextAlignment = TextAlignment.CenterLeft;
            //btnUpper.TextColor = UserCenterColor.Current.Red;
            //btnUpper.Text = wrongIcon + UpperMsg;
            //this.AddChidren(btnUpper);
 
            //btnLower = UserCenterControls.MakeViewButton(width, height, true);
            //btnLower.X = XX;
            //btnLower.Y = btnUpper.Bottom + Application.GetRealHeight(6);
            //btnLower.TextAlignment = TextAlignment.CenterLeft;
            //btnLower.TextColor = UserCenterColor.Current.Red;
            //btnLower.Text = wrongIcon + LowerMsg;
            //this.AddChidren(btnLower);
 
            //btnNumber = UserCenterControls.MakeViewButton(width, height, true);
            //btnNumber.X = XX;
            //btnNumber.Y = btnLower.Bottom + Application.GetRealHeight(6);
            //btnNumber.TextAlignment = TextAlignment.CenterLeft;
            //btnNumber.TextColor = UserCenterColor.Current.Red;
            //btnNumber.Text = wrongIcon + NumberMsg;
            //this.AddChidren(btnNumber);
 
            //btnOther = UserCenterControls.MakeViewButton(width, height, true);
            //btnOther.X = XX;
            //btnOther.Y = btnNumber.Bottom + Application.GetRealHeight(6);
            //btnOther.TextAlignment = TextAlignment.CenterLeft;
            //btnOther.TextColor = UserCenterColor.Current.Red;
            //this.AddChidren(btnOther);
        }
 
        /// <summary>
        /// 密码检测
        /// </summary>
        /// <returns><c>true</c>, if password was checked, <c>false</c> otherwise.</returns>
        /// <param name="password">Password.</param>
        public bool CheckPassword(string password)
        {
            btnOther.Visible = false;
 
            //判断密码长度 
            bool flag1 = password.Length >= 8;
            if (flag1)
            {
                btnLength.TextColor = UserCenterColor.Current.Green;
                btnLength.Text = rightIcon + LengthMsg;
            }
            else
            {
                btnLength.TextColor = UserCenterColor.Current.Red;
                btnLength.Text = wrongIcon + LengthMsg;
            }
 
            //判断是否包含大写字母
            bool flag2 = UserCenterLogic.CheckContainUpper(password);
            if (flag2 == true)
            {
                btnUpper.TextColor = UserCenterColor.Current.Green;
                btnUpper.Text = rightIcon + UpperMsg;
            }
            else
            {
                btnUpper.TextColor = UserCenterColor.Current.Red;
                btnUpper.Text = wrongIcon + UpperMsg;
            }
 
            //判断是否包含小写字母
            bool flag3 = UserCenterLogic.CheckContainLower(password);
            if (flag3 == true)
            {
                btnLower.TextColor = UserCenterColor.Current.Green;
                btnLower.Text = rightIcon + LowerMsg;
            }
            else
            {
                btnLower.TextColor = UserCenterColor.Current.Red;
                btnLower.Text = wrongIcon + LowerMsg;
            }
 
            //判断是否包含数字或者符号
            bool flag4 = UserCenterLogic.CheckContainNum(password);
            bool flag5 = UserCenterLogic.CheckContainSymbol(password);
            if (flag4 == true && flag5 == true)
            {
                btnNumber.TextColor = UserCenterColor.Current.Green;
                btnNumber.Text = rightIcon + NumberMsg;
            }
            else
            {
                btnNumber.TextColor = UserCenterColor.Current.Red;
                btnNumber.Text = wrongIcon + NumberMsg;
            }
            IsError = flag1 && flag2 && flag3 && flag4 && flag5;
 
            return IsError;
        }
 
        /// <summary>
        /// 在最后一行显示其它错误信息
        /// </summary>
        /// <param name="error">Error.</param>
        public void ShowOtherError(string error)
        {
            IsError = true;
            btnOther.Text = wrongIcon + error;
            btnOther.Visible = true;
        }
    }
}