Skip to content

Commit

Permalink
Merge pull request #7 from zeoflow/password-type
Browse files Browse the repository at this point in the history
Updated PasswordModel
  • Loading branch information
teogor committed Oct 3, 2020
2 parents 30f2b57 + 0d275c8 commit df8b58d
Show file tree
Hide file tree
Showing 31 changed files with 418 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 2
update_configs:
updates:
- package-ecosystem: "pip"
directory: "/null"
schedule:
Expand Down
8 changes: 0 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,4 @@ ext {
versionCode = 1
versionName = "1.0.0"

androidx = [
appcompat: 'androidx.appcompat:appcompat:1.0.0',
]

zeoflow = [
password_strength: 'com.zeoflow:password-strength:1.0.0'
]

}
2 changes: 1 addition & 1 deletion password-strength/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.core:core-ktx:+"
implementation "androidx.core:core-ktx:1.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.zeoflow.password.strength

class PasswordModel internal constructor(var passwordType: PasswordType, var content: String, var color: Int)
class PasswordModel internal constructor(var passwordType: PasswordType, var currentScore: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
public class PasswordStrength
{

//--------REQUIREMENTS--------
static int REQUIRED_LENGTH = 8;
static int MAXIMUM_LENGTH = 15;
static boolean REQUIRE_SPECIAL_CHARACTERS = true;
static boolean REQUIRE_DIGITS = true;
static boolean REQUIRE_LOWER_CASE = true;
static boolean REQUIRE_UPPER_CASE = false;
int REQUIRED_LENGTH = 8;
int MAXIMUM_LENGTH = 50;
boolean REQUIRE_SPECIAL_CHARACTERS = true;
boolean REQUIRE_DIGITS = true;
boolean REQUIRE_LOWER_CASE = true;
boolean REQUIRE_UPPER_CASE = false;

PasswordStrength()
{
Expand All @@ -26,7 +25,37 @@ public static PasswordStrength initializePassChecker()
return new PasswordStrength();
}

public PasswordType calculateStrength(String password)
public PasswordStrength withRequiredLength(int requiredLength) {
this.REQUIRED_LENGTH = requiredLength;
return this;
}

public PasswordStrength withMaximumLength(int maximumLength) {
this.MAXIMUM_LENGTH = maximumLength;
return this;
}

public PasswordStrength requireSpecialCharacters(boolean requireSpecialCharacters) {
this.REQUIRE_SPECIAL_CHARACTERS = requireSpecialCharacters;
return this;
}

public PasswordStrength requireDigits(boolean requireDigits) {
this.REQUIRE_DIGITS = requireDigits;
return this;
}

public PasswordStrength requireLowerCase(boolean requireLowerCase) {
this.REQUIRE_LOWER_CASE = requireLowerCase;
return this;
}

public PasswordStrength requireUpperCase(boolean requireUpperCase) {
this.REQUIRE_UPPER_CASE = requireUpperCase;
return this;
}

public PasswordModel calculateStrength(String password)
{
int currentScore = 0;
boolean sawUpper = false;
Expand Down Expand Up @@ -88,17 +117,17 @@ public PasswordType calculateStrength(String password)
switch (currentScore)
{
case 0:
return WEAK;
return new PasswordModel(WEAK, currentScore);
case 1:
return MEDIUM;
return new PasswordModel(MEDIUM, currentScore);
case 2:
return STRONG;
return new PasswordModel(STRONG, currentScore);
case 3:
return VERY_STRONG;
return new PasswordModel(VERY_STRONG, currentScore);
default:
}

return VERY_STRONG;
return new PasswordModel(VERY_STRONG, currentScore);
}

}
1 change: 1 addition & 0 deletions sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.zeoflow.password.strength"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true;
}

lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.browser:browser:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'androidx.core:core:1.3.1'
implementation 'androidx.exifinterface:exifinterface:1.3.0'
implementation 'androidx.annotation:annotation-experimental:1.0.0'
implementation 'androidx.fragment:fragment:1.2.5'
implementation 'androidx.lifecycle:lifecycle-runtime:2.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'
implementation 'androidx.transition:transition:1.4.0-beta01'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'

implementation project(':password-strength')

}
17 changes: 17 additions & 0 deletions sample/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/jakubkinst/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
23 changes: 23 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zeoflow.anidero.sample">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.zeoflow.anidero.sample.MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
29 changes: 29 additions & 0 deletions sample/src/main/java/com/zeoflow/anidero/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.zeoflow.anidero.sample;

import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.zeoflow.password.strength.PasswordModel;
import com.zeoflow.password.strength.PasswordType;

import static com.zeoflow.password.strength.PasswordStrength.initializePassChecker;

public class MainActivity extends AppCompatActivity
{

@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

PasswordModel zPasswordStrength = initializePassChecker()
.requireDigits(true)
.requireUpperCase(true)
.calculateStrength("3454g36v5!?n4vt45j6");

}
}
Loading

0 comments on commit df8b58d

Please sign in to comment.