Imports System
Imports System.Web

Partial Class Admin_CharterContentManagement_ChangePassword
    Inherits AdminPage

	Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim username As String = Me.UserData.UserName
		Dim _passwordUpdated As Boolean
		Dim _count As Integer = 0

        '# 
        Dim regularEx1 As Regex = New Regex("^.*(?=.{8,})(?=.*\d).*$") 'must have number
        Dim regularEx2 As Regex = New Regex("^.*(?=.{8,})(?=.*[a-z]).*$") 'must have small letters
        Dim regularEx3 As Regex = New Regex("^.*(?=.{8,})(?=.*[A-Z]).*$") 'must have capital letters
        Dim regularEx4 As Regex = New Regex("^.*(?=.{8,})(?=.*[!$#%]).*$") 'must have any of the following special characters !$#%
		Dim _userid As Integer
		Dim _password As String = txtNewPassword.Text.ToString()
		Dim match As Boolean = regularEx1.Match(_password).Success

		If regularEx1.Match(_password).Success Then
			_count = _count + 1
		End If
		If regularEx2.Match(_password).Success Then
			_count = _count + 1
		End If

		If regularEx3.Match(_password).Success Then
			_count = _count + 1
		End If
		If regularEx4.Match(_password).Success Then
			_count = _count + 1
		End If

        'the password must satisfy 3 of the fout criteria to be valid
		If (_count >= 3) Then

			Dim CMS As New CMS.CMSService()
			CMS.Credentials = Net.CredentialCache.DefaultNetworkCredentials
			_userid = CType(CMS.GetUserID(txtUser.Text.ToString()), Integer)
			_passwordUpdated = CMS.UpdatePassword(_userid, _password)
			lblError.Visible = True
			If (_passwordUpdated) Then
				lblError.Text = "Password is successfully Updated"
				Response.Redirect("LogIn.aspx?status=success")
			Else
				lblError.Text = "Password is not updated"

			End If
		Else
			lblError.Visible = True
			lblError.Text = "Password is not valid"
        End If

	End Sub

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim username As String = Me.UserData.UserName 'Request.QueryString("username")
		txtUser.Text = username
	End Sub
End Class
