CheckPasswordStrength | 一个检测密码强度的Java工具库。

 by   venshine Java Updated: 8 months ago - Current License: Apache-2.0

Download this library from

Build Applications

kandi X-RAY | CheckPasswordStrength REVIEW AND RATINGS

🔥 一个检测密码强度的Java工具库。

kandi-support
Support

  • CheckPasswordStrength has a low active ecosystem.
  • It has 45 star(s) with 22 fork(s).
  • It had no major release in the last 12 months.
  • It has a neutral sentiment in the developer community.

quality kandi
Quality

  • CheckPasswordStrength has 0 bugs and 0 code smells.

security
Security

  • CheckPasswordStrength has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • CheckPasswordStrength code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.

license
License

  • CheckPasswordStrength is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.

build
Reuse

  • CheckPasswordStrength releases are not available. You will need to build from source code and install.
  • CheckPasswordStrength has no build file. You will be need to create the build yourself to build the component from source.
  • CheckPasswordStrength saves you 90 person hours of effort in developing the same functionality from scratch.
  • It has 231 lines of code, 8 functions and 2 files with 0 % test coverage
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

CheckPasswordStrength Key Features

Email:venshine.cn@gmail.com

CheckPasswordStrength examples and code snippets

  • default
  • JQuery disable submit button till form is completely filled
  • How to submit a Form using Selenium in Java
  • NSPredicate Password Format
  • Angular forms custom validator null return not removing error from form
  • asp.net onkeyup event for textbox

default

    public static void main(String[] args) {
		String passwd = "2hAj5#mne-ix.86H";
		System.out.println(CheckStrength.checkPasswordStrength(passwd));
	}

JQuery disable submit button till form is completely filled

 $('#registerform> input')
 $('#registerform input')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="{% url 'register' %}" id="registerform" class="sign-up-form" method="POST">
    <h2 class="title">Sign up</h2>
    <div class="row">
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="firstname" placeholder="First name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="secondname" placeholder="Second name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field userfield">
                <i class="fas fa-user"></i>
                <input type="text" id="id_username" name="username" placeholder="Username" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field emailfield">
                <i class="fas fa-envelope"></i>
                <input type="email" id="id_email" name="email" placeholder="Email" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-lock-open"></i>
                <input type="number" name="idno" placeholder="ID/Passport Number" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user-ninja"></i>
                <input type="text" name="nationality" placeholder="Nationality" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field passfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="password" name="password" placeholder="Password" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field cpassfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="cpassword" placeholder="Confirm Password" />
            </div>
        </div>
    </div>
    <input type="submit" id="register" class="btn" style="background-color: #5995fd;!important;" value="Sign up"
        disabled />
    <p class="copy-text">&copy;2020. All Rights Reserved</p>
    <h3 class="copy-text"> Kenya Airways</h3>
</form>

<script>
    //disable submit button
    (function () {

        $('#registerform input').keyup(function () {

            var empty = false;
            $('#registerform input').each(function () {
                if ($(this).val() == '') {
                    empty = true;
                }
            });

            if (empty) {
                $('#register').attr('disabled', 'disabled');
            } else {
                $('#register').removeAttr('disabled');
            }
        });
    })()
</script>
-----------------------
 $('#registerform> input')
 $('#registerform input')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="{% url 'register' %}" id="registerform" class="sign-up-form" method="POST">
    <h2 class="title">Sign up</h2>
    <div class="row">
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="firstname" placeholder="First name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="secondname" placeholder="Second name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field userfield">
                <i class="fas fa-user"></i>
                <input type="text" id="id_username" name="username" placeholder="Username" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field emailfield">
                <i class="fas fa-envelope"></i>
                <input type="email" id="id_email" name="email" placeholder="Email" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-lock-open"></i>
                <input type="number" name="idno" placeholder="ID/Passport Number" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user-ninja"></i>
                <input type="text" name="nationality" placeholder="Nationality" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field passfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="password" name="password" placeholder="Password" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field cpassfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="cpassword" placeholder="Confirm Password" />
            </div>
        </div>
    </div>
    <input type="submit" id="register" class="btn" style="background-color: #5995fd;!important;" value="Sign up"
        disabled />
    <p class="copy-text">&copy;2020. All Rights Reserved</p>
    <h3 class="copy-text"> Kenya Airways</h3>
</form>

<script>
    //disable submit button
    (function () {

        $('#registerform input').keyup(function () {

            var empty = false;
            $('#registerform input').each(function () {
                if ($(this).val() == '') {
                    empty = true;
                }
            });

            if (empty) {
                $('#register').attr('disabled', 'disabled');
            } else {
                $('#register').removeAttr('disabled');
            }
        });
    })()
</script>
-----------------------
 $('#registerform> input')
 $('#registerform input')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="{% url 'register' %}" id="registerform" class="sign-up-form" method="POST">
    <h2 class="title">Sign up</h2>
    <div class="row">
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="firstname" placeholder="First name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="secondname" placeholder="Second name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field userfield">
                <i class="fas fa-user"></i>
                <input type="text" id="id_username" name="username" placeholder="Username" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field emailfield">
                <i class="fas fa-envelope"></i>
                <input type="email" id="id_email" name="email" placeholder="Email" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-lock-open"></i>
                <input type="number" name="idno" placeholder="ID/Passport Number" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user-ninja"></i>
                <input type="text" name="nationality" placeholder="Nationality" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field passfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="password" name="password" placeholder="Password" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field cpassfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="cpassword" placeholder="Confirm Password" />
            </div>
        </div>
    </div>
    <input type="submit" id="register" class="btn" style="background-color: #5995fd;!important;" value="Sign up"
        disabled />
    <p class="copy-text">&copy;2020. All Rights Reserved</p>
    <h3 class="copy-text"> Kenya Airways</h3>
</form>

<script>
    //disable submit button
    (function () {

        $('#registerform input').keyup(function () {

            var empty = false;
            $('#registerform input').each(function () {
                if ($(this).val() == '') {
                    empty = true;
                }
            });

            if (empty) {
                $('#register').attr('disabled', 'disabled');
            } else {
                $('#register').removeAttr('disabled');
            }
        });
    })()
</script>
-----------------------
const checkPasswordStrength = () => { return true}; // replace with yours
const cpassword = () => { return true };

$(function() {
  const $inputs = $('#registerform :input');
  $inputs.on("input", function() {
    let valid = true;
    if (this.id === "password") valid = valid && checkPasswordStrength()
    else if (this.id === "cpassword") valid = valid && cpassword()
    const empty = $inputs.filter(function() {
      return $(this).val().trim() == ''}).get();
    valid = valid && empty.length===0;
    
    $('#register').attr('disabled', !valid);
  }).trigger('input')
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="{% url 'register' %}" id="registerform" class="sign-up-form" method="POST">
<h2 class="title">Sign up</h2>
<div class="row">
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-user"></i>
      <input type="text" name="firstname" placeholder="First name" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-user"></i>
      <input type="text" name="secondname" placeholder="Second name" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field userfield">
      <i class="fas fa-user"></i>
      <input type="text" id="id_username" name="username" placeholder="Username" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field emailfield">
      <i class="fas fa-envelope"></i>
      <input type="email" id="id_email" name="email" placeholder="Email" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-lock-open"></i>
      <input type="number" name="idno" placeholder="ID/Passport Number" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-user-ninja"></i>
      <input type="text" name="nationality" placeholder="Nationality" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field passfield">
      <i class="fas fa-lock"></i>
      <input type="password" id="password"  name="password" placeholder="Password" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field cpassfield">
      <i class="fas fa-lock"></i>
      <input type="password" id="cpassword" placeholder="Confirm Password" />
    </div>
  </div>
</div>
<input type="submit" id="register" class="btn" style="background-color: #5995fd;!important;" value="Sign up" disabled/>
<p class="copy-text">&copy;2020. All Rights Reserved</p>
<h3 class="copy-text"> Kenya Airways</h3>
</form>
-----------------------
const checkPasswordStrength = () => { return true}; // replace with yours
const cpassword = () => { return true };

$(function() {
  const $inputs = $('#registerform :input');
  $inputs.on("input", function() {
    let valid = true;
    if (this.id === "password") valid = valid && checkPasswordStrength()
    else if (this.id === "cpassword") valid = valid && cpassword()
    const empty = $inputs.filter(function() {
      return $(this).val().trim() == ''}).get();
    valid = valid && empty.length===0;
    
    $('#register').attr('disabled', !valid);
  }).trigger('input')
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="{% url 'register' %}" id="registerform" class="sign-up-form" method="POST">
<h2 class="title">Sign up</h2>
<div class="row">
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-user"></i>
      <input type="text" name="firstname" placeholder="First name" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-user"></i>
      <input type="text" name="secondname" placeholder="Second name" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field userfield">
      <i class="fas fa-user"></i>
      <input type="text" id="id_username" name="username" placeholder="Username" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field emailfield">
      <i class="fas fa-envelope"></i>
      <input type="email" id="id_email" name="email" placeholder="Email" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-lock-open"></i>
      <input type="number" name="idno" placeholder="ID/Passport Number" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field">
      <i class="fas fa-user-ninja"></i>
      <input type="text" name="nationality" placeholder="Nationality" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field passfield">
      <i class="fas fa-lock"></i>
      <input type="password" id="password"  name="password" placeholder="Password" />
    </div>
  </div>
  <div class="col-md-6">
    <div class="input-field cpassfield">
      <i class="fas fa-lock"></i>
      <input type="password" id="cpassword" placeholder="Confirm Password" />
    </div>
  </div>
</div>
<input type="submit" id="register" class="btn" style="background-color: #5995fd;!important;" value="Sign up" disabled/>
<p class="copy-text">&copy;2020. All Rights Reserved</p>
<h3 class="copy-text"> Kenya Airways</h3>
</form>

How to submit a Form using Selenium in Java

Actions action = new Actions(driver);
WebElement btnElement=driver.findElement(By.xpath("//a[@id='createAccountButton']"));
action.doubleClick(btnElement).build().perform();
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("createAccountButton")));
-----------------------
Actions action = new Actions(driver);
WebElement btnElement=driver.findElement(By.xpath("//a[@id='createAccountButton']"));
action.doubleClick(btnElement).build().perform();
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("createAccountButton")));
-----------------------
 System.setProperty("webdriver.chrome.driver", "./ChromeDriver/chromedriver.exe");

 WebDriver driver = new ChromeDriver();
 driver.get("URL Here");

 WebElement element9 = driver.findElement(By.id("accountname"));
 element9.sendKeys(username);

 WebElement element10 = driver.findElement(By.id("password"));
 element10.sendKeys(password);

 WebElement element12 = driver.findElement(By.id("reenter_password"));
 element12.sendKeys(password);

 element12.click();
 element12.submit();

NSPredicate Password Format

@"^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%?])[0-9A-Za-z!@#$%?]{8,20}$"

Angular forms custom validator null return not removing error from form

return { passwordMatch: true };
// allow blank for when they don't want to change password
if (passwordCtrl.value === '' && passwordConfirmCtrl.value === '') {
  console.log('both are blank');
  control.get('passwordConfirm').setErrors(null);
  return null;
}

if (passwordCtrl.value !== passwordConfirmCtrl.value) {
  console.log('hit mismatch passwords');
  control.get('passwordConfirm').setErrors( { passwordMatch: true } );
  return { passwordMatch: true }
}
-----------------------
return { passwordMatch: true };
// allow blank for when they don't want to change password
if (passwordCtrl.value === '' && passwordConfirmCtrl.value === '') {
  console.log('both are blank');
  control.get('passwordConfirm').setErrors(null);
  return null;
}

if (passwordCtrl.value !== passwordConfirmCtrl.value) {
  console.log('hit mismatch passwords');
  control.get('passwordConfirm').setErrors( { passwordMatch: true } );
  return { passwordMatch: true }
}

asp.net onkeyup event for textbox

<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()"></asp:TextBox>
<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()" ClientMode="Static"></asp:TextBox>
var passwordTextbox = document.getElementById("<%=tb_password.ClientID%>");
.
.
.
.
document.getElementById("<%=lbl_passwordStrength.ClientID%>").innerHTML = strength;
passwordTextbox.style.color = "white";
passwordTextbox.style.backgroundColor = backgroundColor;
-----------------------
<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()"></asp:TextBox>
<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()" ClientMode="Static"></asp:TextBox>
var passwordTextbox = document.getElementById("<%=tb_password.ClientID%>");
.
.
.
.
document.getElementById("<%=lbl_passwordStrength.ClientID%>").innerHTML = strength;
passwordTextbox.style.color = "white";
passwordTextbox.style.backgroundColor = backgroundColor;
-----------------------
<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()"></asp:TextBox>
<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()" ClientMode="Static"></asp:TextBox>
var passwordTextbox = document.getElementById("<%=tb_password.ClientID%>");
.
.
.
.
document.getElementById("<%=lbl_passwordStrength.ClientID%>").innerHTML = strength;
passwordTextbox.style.color = "white";
passwordTextbox.style.backgroundColor = backgroundColor;

COMMUNITY DISCUSSIONS

Top Trending Discussions on CheckPasswordStrength
  • JQuery disable submit button till form is completely filled
  • How to submit a Form using Selenium in Java
  • NSPredicate Password Format
  • Angular forms custom validator null return not removing error from form
  • asp.net onkeyup event for textbox
Top Trending Discussions on CheckPasswordStrength

QUESTION

JQuery disable submit button till form is completely filled

Asked 2021-Jan-11 at 06:12

I am trying to implement a jquery function to diable submit button till all values are filled please help as I seem not to find a solution to it..Where am I going wrong?

Here is the html:

<form action="{% url 'register' %}" id="registerform" class="sign-up-form" method="POST">
                {% csrf_token %}
                <h2 class="title">Sign up</h2>
                <div class="row">
                    <div class="col-md-6">
                        <div class="input-field">
                            <i class="fas fa-user"></i>
                            <input type="text" name="firstname" placeholder="First name"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="input-field">
                            <i class="fas fa-user"></i>
                            <input type="text" name="secondname" placeholder="Second name"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="input-field userfield">
                            <i class="fas fa-user"></i>
                            <input type="text" id="id_username" name="username" placeholder="Username"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="input-field emailfield">
                            <i class="fas fa-envelope"></i>
                            <input type="email" id="id_email" name="email" placeholder="Email"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="input-field">
                            <i class="fas fa-lock-open"></i>
                            <input type="number" name="idno" placeholder="ID/Passport Number"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="input-field">
                            <i class="fas fa-user-ninja"></i>
                            <input type="text" name="nationality" placeholder="Nationality"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="input-field passfield">
                            <i class="fas fa-lock"></i>
                            <input type="password" id="password" onkeyup="checkPasswordStrength();" name="password"
                                   placeholder="Password"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="input-field cpassfield">
                            <i class="fas fa-lock"></i>
                            <input type="password" id="cpassword" onkeyup="cpassword();"
                                   placeholder="Confirm Password"/>
                        </div>
                    </div>
                </div>
                <input type="submit" id="register" class="btn" style="background-color: #5995fd;!important;"
                       value="Sign up" disabled/>
                <p class="copy-text">&copy;2020. All Rights Reserved</p>
                <h3 class="copy-text"> Kenya Airways</h3>
            </form>

and the javascript:

<script>
    //disable submit button
    (function () {

        $('#registerform > input').keyup(function () {

            var empty = false;
            $('#registerform> input').each(function () {
                if ($(this).val() == '') {
                    empty = true;
                }
            });

            if (empty) {
                $('#register').attr('disabled', 'disabled');
            } else {
                $('#register').removeAttr('disabled');
            }
        });
    })()
</script>

Please help me solve the above as the button is still disabled even after all forms are submitted.

ANSWER

Answered 2021-Jan-10 at 08:21

$('#registerform> input') selects only looks at the immediate children(input) of registerform.

Error

 $('#registerform> input')

Fix

 $('#registerform input')

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="{% url 'register' %}" id="registerform" class="sign-up-form" method="POST">
    <h2 class="title">Sign up</h2>
    <div class="row">
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="firstname" placeholder="First name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user"></i>
                <input type="text" name="secondname" placeholder="Second name" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field userfield">
                <i class="fas fa-user"></i>
                <input type="text" id="id_username" name="username" placeholder="Username" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field emailfield">
                <i class="fas fa-envelope"></i>
                <input type="email" id="id_email" name="email" placeholder="Email" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-lock-open"></i>
                <input type="number" name="idno" placeholder="ID/Passport Number" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field">
                <i class="fas fa-user-ninja"></i>
                <input type="text" name="nationality" placeholder="Nationality" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field passfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="password" name="password" placeholder="Password" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-field cpassfield">
                <i class="fas fa-lock"></i>
                <input type="password" id="cpassword" placeholder="Confirm Password" />
            </div>
        </div>
    </div>
    <input type="submit" id="register" class="btn" style="background-color: #5995fd;!important;" value="Sign up"
        disabled />
    <p class="copy-text">&copy;2020. All Rights Reserved</p>
    <h3 class="copy-text"> Kenya Airways</h3>
</form>

<script>
    //disable submit button
    (function () {

        $('#registerform input').keyup(function () {

            var empty = false;
            $('#registerform input').each(function () {
                if ($(this).val() == '') {
                    empty = true;
                }
            });

            if (empty) {
                $('#register').attr('disabled', 'disabled');
            } else {
                $('#register').removeAttr('disabled');
            }
        });
    })()
</script>

Source https://stackoverflow.com/questions/65651233

QUESTION

How to submit a Form using Selenium in Java

Asked 2018-Dec-23 at 20:18

I am using Selenium WebDriver to automate a system. Language is Java. I have done most of the things but I am stuck at one point. I need to submit a Form that contains Username, Password and Re-Entering Password fields. But when I fill them(using selenium) and click the Create Account button It didn't work.

Here is the code,

    System.setProperty("webdriver.chrome.driver", "./ChromeDriver/chromedriver.exe");

    WebDriver driver = new ChromeDriver();
    driver.get("URL Here");

    WebElement element9 = driver.findElement(By.id("accountname"));
    element9.sendKeys(username);

    WebElement element10 = driver.findElement(By.id("password"));
    element10.sendKeys(password);

    WebElement element12 = driver.findElement(By.id("reenter_password"));
    element12.sendKeys(password);

I used these methods to submit the form. But none of them worked.

    element12.sendKeys(Keys.ENTER); //method 1

    WebElement element11 = driver.findElement(By.linkText("Complete Sign-up"));
    element11.click(); //method 2

    ((JavascriptExecutor)driver).executeScript("javascript:CompleteCreateAccount();"); //method 3

    WebElement element13 = driver.findElement(By.xpath("//a[@id='createAccountButton']/span"));
    element13.click(); //method 4

    element13.submit(); //method 5

    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", element13); //method 6

Form HTML got from Inspect Element,

<div class="leftcol">
<div id="error_display" style="display: none;"></div>
    <div class="checkout_content_box" id="cart_area">
        <form id="create_account" name="create_account" action="" onsubmit="CompleteCreateAccount(); return false; " method="POST">
            <input type="hidden" name="lt" id="lt" value="0">
            <div id="account_form_box">
                <div class="join_form">
                    <div class="form_row">
                        <div class="form_area">
                            <label for="accountname">Create a Steam account name</label>
                            <input type="text" maxlength="64" name="accountname" id="accountname" onchange="CheckAccountNameAvailability();">
                        </div>
                        <div class="form_notes">
                            <br>
                            <span class="input_note"><a href="javascript:CheckAccountNameAvailability();">Check availability</a></span>
                            <span id="accountname_availability" style="display: none;"></span>
                        </div>
                    <div style="clear: left;"></div>
                </div>
                <div id="form_row_choose_suggested_name" class="form_row" style="display: none;">
                    <div class="form_area">
                        <label for="choose_accountname">Available account names</label><br>
                        <select id="choose_accountname" name="choose_accountname" size="3" onchange="UpdateAccountName( this.value );">
                            <option id="suggested_name_1"></option>
                            <option id="suggested_name_2"></option>
                            <option id="suggested_name_3"></option>
                        </select>
                    </div>
                    <div class="form_notes">
                        <br>
                        <span class="choose_accountname_description">Select one or try again with another name of your choice</span>
                    </div>
                    <div style="clear: left;"></div>
                </div>
                <div class="rule"></div>
                <div class="form_row">
                    <div class="form_area">
                        <label for="password">Choose a password</label>
                        <input type="password" maxlength="64" name="password" id="password" onkeyup="CheckPasswordStrength()" autocomplete="off">
                    </div>
                    <div class="form_notes">
                        <div id="password_tag" class="password_tag">&nbsp;</div>
                    </div>
                    <div style="clear: left;"></div>
                </div>
                <div class="form_row">
                    <div class="form_area">
                        <label class="reenter_row" for="reenter_password">Re-enter password</label>
                        <input type="password" maxlength="64" name="reenter_password" id="reenter_password" onkeyup="ReenterPasswordChange()" autocomplete="off">
                    </div>
                    <div class="form_notes">
                        <br>
                        <div id="reenter_tag" class="password_tag">&nbsp;</div>
                    </div>
                    <div style="clear: left;"></div>
                </div>
                <div class="rule"></div>

                <div class="form_row">
                    <div id="priv_and_sub">
                        <a id="createAccountButton" class="btnv6_blue_hoverfade btn_medium" href="javascript:CompleteCreateAccount();" style="float: right;">
                            <span>Complete Sign-up</span>
                        </a>

                        <div style="clear: right;"></div>
                    </div>
                    <div id="ssa_submit">
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

And also I need to say when I click Create Account button manually it is working. But using selenium It is not working and pass this message

The account name you have chosen is not available. Please choose another name. The password you entered is not allowed. Please select a different password, with at least 8 characters.

But username and passwords are okay. Nothing wrong. Because when I click it manually It is working with that username and password.

ANSWER

Answered 2018-Dec-23 at 14:14

I have had similar issue's in the past sometimes it helps to focus on a different element then click...

I'd start with trying to focus on <div id="ssa_submit"></div>.

EDIT:

You say that manually it works so what I'll advise you to use Action like so:

Actions action = new Actions(driver);
WebElement btnElement=driver.findElement(By.xpath("//a[@id='createAccountButton']"));
action.doubleClick(btnElement).build().perform();

But it could be you really have a bug in the system...

EDIT 2:

A best practice in Selenium is to use WebDriverWait with ExpectedConditions:

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("createAccountButton")));

See ExpectedConditions and WebDriverWait.

I think this should do the job!

Hope this helps you.

Source https://stackoverflow.com/questions/53902702

QUESTION

NSPredicate Password Format

Asked 2018-Apr-27 at 20:24

I'm trying to figure out an accurate solution for validating a password field using NSPredicate. Here's my code:

-(int)checkPasswordStrength:(NSString *)password
{
    NSPredicate *validPassword = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",@"\\b^(?=.*[0-9]+?)(?=.*[A-Z]+?)(?=.*[a-z]*?)(?=.*[!@#$%?]+?)[0-9A-z!@#$%?]{8,20}$\\b"];
    NSString *escapedPassword = [NSRegularExpression escapedPatternForString:password];
    if(![validPassword evaluateWithObject:escapedPassword]) {
        [Helper showAlertWithTitle:@"" Message:@"Password should contain 8 to 20 alphanumeric characters, one capitalized letter, and with at least one of the symbols (e.g. !@#$%?)"];
        return 0;
    }

    return 1;
}

I've tried the patterns:

\\b^(?=.*[0-9]+?)(?=(.*\\d){1})(?=.*[a-zA-Z])(?=.*[!@#$%?]).*[0-9a-zA-Z!@#$%?]{8,20}\\b

\\b^(?=.*[0-9]+?)(?=.*[A-Z]+?)(?=.*[a-z]*?)(?=.*[!@#$%?]+?)[0-9A-z!@#$%?]{8,20}$\\b

\\b^(?=.*[0-9]+?)(?=.*[A-Z]+?)(?=.*[a-z]*?)(?=.*[!@#$%?]+?)[0-9A-z!@#$%?]{8,20}$\\b

... Both without escaping and escaping the strings, but it would not just work for this type of password patterns (wherein the special characters are found after the first and last password string):

OverAndUnder21!
AreYouHere2?
PleaseDial9#
!4Ngrier!
!D4ngerZone

All the other passwords work:

P@MyF8fulDog
classM8s4L!fe

And so on...

I tried to test my RegEx patterns in regex101.com, and it seems to have a full match.

What is the right validation pattern in NSPredicate to allow the special characters as the first and last characters?

ANSWER

Answered 2018-Apr-27 at 20:24

You need to remove word boundaries and add a question mark to the pattern:

@"^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%?])[0-9A-Za-z!@#$%?]{8,20}$"

See the regex demo.

The word boundary at the start and end of the pattern requires the first and last char to be a word char (a letter, digit or _).

Also, note +? is not necessary inside lookaheads as you just require at least 1 instance of the patterns.

Source https://stackoverflow.com/questions/50068761

QUESTION

Angular forms custom validator null return not removing error from form

Asked 2018-Feb-21 at 03:02

So I've created a custom validator to verify that the confirm password input matches the original entry. Works fine. However, I'm allowing that both fields be blank since this is on a page where someone can change their password in their settings, which of course they may not want to do. The form should become valid if both are blank so that it can be submitted and the other settings may be updated for their profile, but something weird is happening.

Form props:

passControl = new FormControl('', [
  FormValidation.checkPasswordStrength()
]);

passConfirmControl = new FormControl('', [
]);

profileForm = new FormGroup(
  {
    password: this.passControl,
    passwordConfirm: this.passConfirmControl
  },
  {
    validators: FormValidation.checkPasswordsMatch()
  }
);

Here's my validation function:

static checkPasswordsMatch(): ValidatorFn {
  return (control: AbstractControl): {[key: string]: any} => {
    let passwordCtrl = control.get('password');
    let passwordConfirmCtrl = control.get('passwordConfirm');

    // allow blank for when they don't want to change password
    if (passwordCtrl.value === '' && passwordConfirmCtrl.value === '') {
      console.log('both are blank');
      return null;
    }

    if (passwordCtrl.value !== passwordConfirmCtrl.value) {
      console.log('hit mismatch passwords');
      control.get('passwordConfirm').setErrors( { passwordMatch: true } );
    }

    return null;
  };
}

So when the form loads, its actually valid and I see both are blank. However, if you touch the password field and type something, and of course it shows that now they don't match, but when you delete what you typed there, then the function shows that they are again both empty, but the error sticks and the form stays invalid, unless you also touch the passwordConfirm field and also type something and delete it. What am I missing?

ANSWER

Answered 2018-Feb-21 at 03:02

You are setting the error on the passwordConfirm FormControl, which your validator doesn't effect when it runs. If you want the error to go away, you'll either need to apply the validator to that specific FormControl, or you'll need to make sure you remove the Error from the control when the previous tests succeeds.

Typically you would return the error within a validator rather than setting it on a specific FormControl. As you are finding out, unless you manually remove the error from the FormControl, it will stick around. Validators will only alter the error objects of the controls they are bound to.

Typically you would just return the error if/when it occurs.

return { passwordMatch: true };

Or if you want to do both and set the FormControl error manually as well.

// allow blank for when they don't want to change password
if (passwordCtrl.value === '' && passwordConfirmCtrl.value === '') {
  console.log('both are blank');
  control.get('passwordConfirm').setErrors(null);
  return null;
}

if (passwordCtrl.value !== passwordConfirmCtrl.value) {
  console.log('hit mismatch passwords');
  control.get('passwordConfirm').setErrors( { passwordMatch: true } );
  return { passwordMatch: true }
}

Also just a nitpicky pedantic thing, you should try to make your errors logically readable. So while you are testing if the password matches, saying passwordMatch: true incinuates that the passwords match. You might be better off naming your errors after the error rather than the test, for example: passwordsDoNotMatch: true. This reads as though there is a password mismatch, which is a more accurate depiction of the issue being presented through the form.

Source https://stackoverflow.com/questions/48895794

QUESTION

asp.net onkeyup event for textbox

Asked 2017-Jul-21 at 10:08

I have an issue with onkeyup event with textbox. my function is to check password strength of the password textbox. so when a users enter his password, it will call the function of checking password strength and show in a label if his password is very weak/weak/medium/strong. Also, the textbox background will show colors according to the strength of the password. however when i type in the password textbox, the label does not show anything and the textbox does not change color.

<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()"  ></asp:TextBox>
                        <script type="text/javascript">
    function checkPasswordStrength()
    {
        var passwordTextbox = document.getElementById("tb_password");
        var password = passwordTextbox.value;
        var specialCharacters = "!@#$%^&*_+";
        var passwordScore = 0;

        for (var i = 0; i < password.length; i++)
        {
            if(specialCharacters.indexOf(password.charAt(i) > -1))
            {
                passwordScore += 20;
            }
        }

        if (/[a-z]/.test(password))
        {
            passwordScore += 20;
        }

        if (/[A-Z]/.test(password)) {
            passwordScore += 20;
        }

        if (password.length >= 8) {
            passwordScore += 20;
        }

        if (/[\d]/.test(password)) {
            passwordScore += 20;
        }

        var strength = "";
        var backgroundColor = "";

        if (passwordScore >= 100)
        {
            strength = "Strong"
            backgroundColor = "green";
        }

        else if (passwordScore >= 80)
        {
            strength = "Medium"
            backgroundColor = "yellow";
        }

        else if (passwordScore >= 60) {
            strength = "Weak"
            backgroundColor = "red";
        }

        else
        {
            strength = "Very Weak"
            backgroundColor = "maroon";
        }

        document.getElementById("lbl_passwordStrength").innerHTML = strength;
        passwordTextbox.style.color = "white";
        passwordTextbox.style.backgroundColor = backgroundColor;
    }

</script>
                        <br />
                        <asp:Label ID="lbl_passwordStrength" runat="server"></asp:Label>

ANSWER

Answered 2017-Jul-21 at 10:08

Every control that is included in an ASP.NET Web page must contain a unique identifier (ID). To maintain this uniqueness ASP.Net change the ID of control when the page gets rendered into HTML.

Here, if below control is inside <asp:ContentPlaceHolder> then the ID is likely to gets changed into ctl00$ctl00$ContentPlaceHolder$tb_password for example.

<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()"></asp:TextBox>

To overcome this what you can do it either use Client Mode in mark-up or use ClientID in javascript.

Method 1:

<asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()" ClientMode="Static"></asp:TextBox>

Method 2:

var passwordTextbox = document.getElementById("<%=tb_password.ClientID%>");
.
.
.
.
document.getElementById("<%=lbl_passwordStrength.ClientID%>").innerHTML = strength;
passwordTextbox.style.color = "white";
passwordTextbox.style.backgroundColor = backgroundColor;

Source https://stackoverflow.com/questions/45233576

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

VULNERABILITIES

No vulnerabilities reported

INSTALL CheckPasswordStrength

You can use CheckPasswordStrength like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the CheckPasswordStrength component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

SUPPORT

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Implement CheckPasswordStrength faster with kandi.

  • Use the support, quality, security, license, reuse scores and reviewed functions to confirm the fit for your project.
  • Use the, Q & A, Installation and Support guides to implement faster.

Discover Millions of Libraries and
Pre-built Use Cases on kandi