ditch password strength indicator
This commit is contained in:
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.dialog;
|
package org.sufficientlysecure.keychain.ui.dialog;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@@ -27,6 +27,7 @@ import android.os.Message;
|
|||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -41,7 +42,6 @@ import android.widget.TextView.OnEditorActionListener;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText;
|
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
|||||||
public static final String MESSAGE_NEW_PASSPHRASE = "new_passphrase";
|
public static final String MESSAGE_NEW_PASSPHRASE = "new_passphrase";
|
||||||
|
|
||||||
private Messenger mMessenger;
|
private Messenger mMessenger;
|
||||||
private PassphraseEditText mPassphraseEditText;
|
private EditText mPassphraseEditText;
|
||||||
private EditText mPassphraseAgainEditText;
|
private EditText mPassphraseAgainEditText;
|
||||||
private CheckBox mNoPassphraseCheckBox;
|
private CheckBox mNoPassphraseCheckBox;
|
||||||
|
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 Schürmann & Breitmoser GbR
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.widget;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.support.v7.widget.AppCompatEditText;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.TypedValue;
|
|
||||||
|
|
||||||
public class PassphraseEditText extends AppCompatEditText {
|
|
||||||
|
|
||||||
PasswordStrengthBarView mPasswordStrengthBarView;
|
|
||||||
int mPasswordBarWidth;
|
|
||||||
int mPasswordBarHeight;
|
|
||||||
float barGap;
|
|
||||||
|
|
||||||
public PassphraseEditText(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
init(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init(Context context, AttributeSet attrs) {
|
|
||||||
mPasswordBarHeight = (int) (8 * getResources().getDisplayMetrics().density);
|
|
||||||
mPasswordBarWidth = (int) (50 * getResources().getDisplayMetrics().density);
|
|
||||||
|
|
||||||
barGap = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
|
||||||
getContext().getResources().getDisplayMetrics());
|
|
||||||
|
|
||||||
this.setPadding(getPaddingLeft(), getPaddingTop(),
|
|
||||||
getPaddingRight() + (int) barGap + mPasswordBarWidth, getPaddingBottom());
|
|
||||||
|
|
||||||
mPasswordStrengthBarView = new PasswordStrengthBarView(context, attrs);
|
|
||||||
mPasswordStrengthBarView.setShowGuides(false);
|
|
||||||
|
|
||||||
this.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
mPasswordStrengthBarView.setPassword(s.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
||||||
super.onLayout(changed, left, top, right, bottom);
|
|
||||||
mPasswordStrengthBarView.layout(0, 0, mPasswordBarWidth, mPasswordBarHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
super.onDraw(canvas);
|
|
||||||
float translateX = getScrollX() + canvas.getWidth() - mPasswordBarWidth;
|
|
||||||
float translateY = (canvas.getHeight() - mPasswordBarHeight) / 2;
|
|
||||||
canvas.translate(translateX, translateY);
|
|
||||||
mPasswordStrengthBarView.draw(canvas);
|
|
||||||
canvas.translate(-translateX, -translateY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014 Matt Allen
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.widget;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by matt on 04/07/2014.
|
|
||||||
* https://github.com/matt-allen/android-password-strength-indicator
|
|
||||||
*/
|
|
||||||
public class PasswordStrengthBarView extends PasswordStrengthView {
|
|
||||||
|
|
||||||
public PasswordStrengthBarView(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
mMinHeight = 80;
|
|
||||||
mMinWidth = 300;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
super.onDraw(canvas);
|
|
||||||
generateIndicatorColor();
|
|
||||||
// Default to full width
|
|
||||||
int indWidth = mIndicatorWidth;
|
|
||||||
// If score, leave it as full - can cause it to become
|
|
||||||
// less than full width in this calculation
|
|
||||||
if (mCurrentScore < 20) indWidth = (mIndicatorWidth / 20) * mCurrentScore;
|
|
||||||
// Draw indicator
|
|
||||||
canvas.drawRect(
|
|
||||||
getPaddingLeft(),
|
|
||||||
getPaddingTop(),
|
|
||||||
indWidth,
|
|
||||||
mIndicatorHeight,
|
|
||||||
mIndicatorPaint
|
|
||||||
);
|
|
||||||
// Draw guides if true
|
|
||||||
if (mShowGuides) {
|
|
||||||
// TODO: Try and do this with a loop, for efficiency
|
|
||||||
// Draw bottom guide border
|
|
||||||
float positionY = getHeight() - getPaddingBottom() - getPaddingTop();
|
|
||||||
float notchHeight = (float) (positionY * 0.8);
|
|
||||||
canvas.drawLine(
|
|
||||||
getPaddingLeft(),
|
|
||||||
positionY,
|
|
||||||
getWidth() - getPaddingRight(),
|
|
||||||
positionY,
|
|
||||||
mGuidePaint);
|
|
||||||
// Show left-most notch
|
|
||||||
canvas.drawLine(
|
|
||||||
getPaddingLeft(),
|
|
||||||
positionY,
|
|
||||||
getPaddingLeft(),
|
|
||||||
notchHeight,
|
|
||||||
mGuidePaint
|
|
||||||
);
|
|
||||||
// Show middle-left notch
|
|
||||||
canvas.drawLine(
|
|
||||||
(float) (mIndicatorWidth * 0.25) + getPaddingLeft(),
|
|
||||||
positionY,
|
|
||||||
(float) (mIndicatorWidth * 0.25) + getPaddingLeft(),
|
|
||||||
notchHeight,
|
|
||||||
mGuidePaint
|
|
||||||
);
|
|
||||||
// Show the middle notch
|
|
||||||
canvas.drawLine(
|
|
||||||
(float) (mIndicatorWidth * 0.5) + getPaddingLeft(),
|
|
||||||
positionY,
|
|
||||||
(float) (mIndicatorWidth * 0.5) + getPaddingLeft(),
|
|
||||||
notchHeight,
|
|
||||||
mGuidePaint
|
|
||||||
);
|
|
||||||
// Show the middle-right notch
|
|
||||||
canvas.drawLine(
|
|
||||||
(float) (mIndicatorWidth * 0.75) + getPaddingLeft(),
|
|
||||||
positionY,
|
|
||||||
(float) (mIndicatorWidth * 0.75) + getPaddingLeft(),
|
|
||||||
notchHeight,
|
|
||||||
mGuidePaint
|
|
||||||
);
|
|
||||||
// Show the right-most notch
|
|
||||||
canvas.drawLine(
|
|
||||||
mIndicatorWidth + getPaddingLeft(),
|
|
||||||
positionY,
|
|
||||||
mIndicatorWidth + getPaddingLeft(),
|
|
||||||
notchHeight,
|
|
||||||
mGuidePaint
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,362 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014 Matt Allen
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.widget;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Matt Allen
|
|
||||||
* 01/07/14
|
|
||||||
* http://www.mattallensoftware.co.uk
|
|
||||||
* mattallen092@gmail.com
|
|
||||||
* <p/>
|
|
||||||
* https://github.com/matt-allen/android-password-strength-indicator
|
|
||||||
* <p/>
|
|
||||||
* <p>
|
|
||||||
* This View is designed to indicate how secure a user-entered password is in a visual way to
|
|
||||||
* relay to the user if they need to make it stronger. The strength of the password can be set
|
|
||||||
* at creation (or after) which will decide whether their password is strong enough.
|
|
||||||
* </p>
|
|
||||||
* <p/>
|
|
||||||
* <p>
|
|
||||||
* The password strength is decided by an index of 20. The minimum score needed to pass is 10
|
|
||||||
* which means the String has met the conditions imposed by the strength test, but can be improved.
|
|
||||||
* If the password scores 10-19 it is considered weak, and only if it scores 20 will it be
|
|
||||||
* considered strong.
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public class PasswordStrengthView extends View {
|
|
||||||
|
|
||||||
protected int mMinWidth;
|
|
||||||
protected int mMinHeight;
|
|
||||||
|
|
||||||
protected Paint mIndicatorPaint;
|
|
||||||
protected Paint mGuidePaint;
|
|
||||||
|
|
||||||
protected int mIndicatorHeight;
|
|
||||||
protected int mIndicatorWidth;
|
|
||||||
protected int mCurrentScore;
|
|
||||||
|
|
||||||
protected int mColorFail;
|
|
||||||
protected int mColorWeak;
|
|
||||||
protected int mColorStrong;
|
|
||||||
|
|
||||||
protected boolean mShowGuides = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to define that the indicator should only be looking
|
|
||||||
* for a weak password. The bare minimum is used here to let
|
|
||||||
* the user continue.
|
|
||||||
*/
|
|
||||||
public static final int STRENGTH_WEAK = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A fairly strict rule for generating a password. It encourages a password that is
|
|
||||||
* less easy to crack.
|
|
||||||
*/
|
|
||||||
public static final int STRENGTH_MEDIUM = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A strong algorithm that encourages very strong passwords that should be fairly long, with
|
|
||||||
* non-alphanumeric, numbers, and upper case.
|
|
||||||
*/
|
|
||||||
public static final int STRENGTH_STRONG = 2;
|
|
||||||
|
|
||||||
private int mStrengthRequirement = -1;
|
|
||||||
protected String mPassword;
|
|
||||||
|
|
||||||
public PasswordStrengthView(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
|
|
||||||
int COLOR_FAIL = getResources().getColor(R.color.password_strength_low);
|
|
||||||
int COLOR_WEAK = getResources().getColor(R.color.password_strength_medium);
|
|
||||||
int COLOR_STRONG = getResources().getColor(R.color.password_strength_high);
|
|
||||||
|
|
||||||
TypedArray style = context.getTheme().obtainStyledAttributes(
|
|
||||||
attrs,
|
|
||||||
R.styleable.PasswordStrengthView,
|
|
||||||
0, 0);
|
|
||||||
|
|
||||||
mStrengthRequirement = style.getInteger(R.styleable.PasswordStrengthView_strength,
|
|
||||||
STRENGTH_MEDIUM);
|
|
||||||
mShowGuides = style.getBoolean(R.styleable.PasswordStrengthView_showGuides, true);
|
|
||||||
mColorFail = style.getColor(R.styleable.PasswordStrengthView_color_fail, COLOR_FAIL);
|
|
||||||
mColorWeak = style.getColor(R.styleable.PasswordStrengthView_color_weak, COLOR_WEAK);
|
|
||||||
mColorStrong = style.getColor(R.styleable.PasswordStrengthView_color_strong,
|
|
||||||
COLOR_STRONG);
|
|
||||||
|
|
||||||
// Create and style the paint used for drawing the guide on the indicator
|
|
||||||
mGuidePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
||||||
mGuidePaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
|
||||||
mGuidePaint.setColor(Color.BLACK);
|
|
||||||
// Create and style paint for indicator
|
|
||||||
mIndicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
||||||
mIndicatorPaint.setStyle(Paint.Style.FILL);
|
|
||||||
|
|
||||||
style.recycle();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This view can determine if the password entered by the user is acceptable for
|
|
||||||
* use by your use case. This is based on the strength requirement you have set.
|
|
||||||
*
|
|
||||||
* @return True if requirement has been met
|
|
||||||
*/
|
|
||||||
public boolean isStrengthRequirementMet() {
|
|
||||||
return (mCurrentScore >= 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change the strength requirement of the password entered by the user. This will also
|
|
||||||
* re-check the password already entered against these new requirements.
|
|
||||||
*
|
|
||||||
* @param requiredStrength Use the public constants of this class to set
|
|
||||||
*/
|
|
||||||
public void setStrengthRequirement(int requiredStrength) {
|
|
||||||
if (requiredStrength >= 0 && requiredStrength <= 2) {
|
|
||||||
mStrengthRequirement = requiredStrength;
|
|
||||||
if (mPassword != null && mPassword.length() > 0) {
|
|
||||||
generatePasswordScore();
|
|
||||||
// Update view with new score
|
|
||||||
invalidate();
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new IndexOutOfBoundsException("Input out of expected range");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the password string to check strength of
|
|
||||||
*
|
|
||||||
* @param passwordString String representation of user-input
|
|
||||||
*/
|
|
||||||
public void setPassword(String passwordString) {
|
|
||||||
if (passwordString != null && passwordString.length() > 0) {
|
|
||||||
mPassword = passwordString;
|
|
||||||
generatePasswordScore();
|
|
||||||
} else {
|
|
||||||
mPassword = "";
|
|
||||||
mCurrentScore = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update view with new score
|
|
||||||
invalidate();
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private convenience method for adding to the password score
|
|
||||||
*
|
|
||||||
* @param score Amount to be added to current score
|
|
||||||
*/
|
|
||||||
protected void addToPasswordScore(int score) {
|
|
||||||
int newScore = mCurrentScore + score;
|
|
||||||
|
|
||||||
// Limit max score
|
|
||||||
if (newScore > 20) {
|
|
||||||
mCurrentScore = 20;
|
|
||||||
} else {
|
|
||||||
mCurrentScore = newScore;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this to determine the current strength requirement set on the algorithm
|
|
||||||
*
|
|
||||||
* @return Int representation of the current strength set for the indicator
|
|
||||||
*/
|
|
||||||
public int getStrengthRequirement() {
|
|
||||||
return mStrengthRequirement;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a score based on the password. The password will already need to be stored
|
|
||||||
* as a class member before running this.
|
|
||||||
*/
|
|
||||||
protected void generatePasswordScore() {
|
|
||||||
mCurrentScore = 0;
|
|
||||||
int upperCase = getUppercaseCount(mPassword);
|
|
||||||
int nonAlpha = getNonAlphanumericCount(mPassword);
|
|
||||||
int numbers = getNumberCount(mPassword);
|
|
||||||
switch (mStrengthRequirement) {
|
|
||||||
case STRENGTH_WEAK:
|
|
||||||
addToPasswordScore(mPassword.length() * 2);
|
|
||||||
addToPasswordScore(upperCase * 2);
|
|
||||||
addToPasswordScore(nonAlpha * 2);
|
|
||||||
addToPasswordScore(numbers * 2);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STRENGTH_MEDIUM:
|
|
||||||
addToPasswordScore(mPassword.length());
|
|
||||||
addToPasswordScore(upperCase);
|
|
||||||
addToPasswordScore(nonAlpha * 2);
|
|
||||||
addToPasswordScore(numbers);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STRENGTH_STRONG:
|
|
||||||
addToPasswordScore(mPassword.length() / 2);
|
|
||||||
// Cut the score in half to make this a very high requirement
|
|
||||||
addToPasswordScore(upperCase);
|
|
||||||
addToPasswordScore(nonAlpha);
|
|
||||||
addToPasswordScore(numbers);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
|
|
||||||
super.onSizeChanged(w, h, oldW, oldH);
|
|
||||||
int paddingX = getPaddingLeft();
|
|
||||||
int paddingY = getPaddingTop();
|
|
||||||
mIndicatorHeight = h - paddingY;
|
|
||||||
mIndicatorWidth = w - paddingX;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The standard parts of the onMeasure needed to create the password strength
|
|
||||||
* indicator. Subclasses should call super.onMeasure, but also need to set
|
|
||||||
* the minimum height and width in the constructor.
|
|
||||||
*
|
|
||||||
* @param widthMeasureSpec The measurement given by the system
|
|
||||||
* @param heightMeasureSpec The measurement given by the system
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
||||||
// Set minimum space for the view to do it's thing
|
|
||||||
int minW = getPaddingLeft() + getPaddingRight() + mMinWidth;
|
|
||||||
int w = resolveSizeAndState(minW, widthMeasureSpec, 1);
|
|
||||||
// And give it enough height so it's visible
|
|
||||||
int minH = mMinHeight + getPaddingBottom() + getPaddingTop();
|
|
||||||
int h = resolveSizeAndState(minH, heightMeasureSpec, 0);
|
|
||||||
// Feed these back into UIKit
|
|
||||||
setMeasuredDimension(w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the colour of the indicator {@code Paint} to one that is appropriate
|
|
||||||
* for the strength of the password.
|
|
||||||
*/
|
|
||||||
protected void generateIndicatorColor() {
|
|
||||||
int color = mColorFail;
|
|
||||||
if (mCurrentScore >= 18) {
|
|
||||||
color = mColorStrong;
|
|
||||||
} else if (mCurrentScore >= 10) {
|
|
||||||
color = mColorWeak;
|
|
||||||
}
|
|
||||||
mIndicatorPaint.setColor(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quick method to determine how many of the characters in a given string are upper case
|
|
||||||
*
|
|
||||||
* @param stringToCheck The string to examine
|
|
||||||
* @return Number of upper case characters
|
|
||||||
*/
|
|
||||||
protected int getUppercaseCount(String stringToCheck) {
|
|
||||||
int score = 0;
|
|
||||||
int loops = stringToCheck.length() - 1;
|
|
||||||
for (int i = 0; i <= loops; i++) {
|
|
||||||
if (Character.isUpperCase(stringToCheck.charAt(i))) {
|
|
||||||
score++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience method to determine how many characters in the given String aren't
|
|
||||||
* letters or numbers.
|
|
||||||
*
|
|
||||||
* @param stringToCheck
|
|
||||||
* @return Number of characters that aren't numbers or letters
|
|
||||||
*/
|
|
||||||
protected int getNonAlphanumericCount(String stringToCheck) {
|
|
||||||
int score = 0;
|
|
||||||
int loops = stringToCheck.length() - 1;
|
|
||||||
for (int i = 0; i <= loops; i++) {
|
|
||||||
if (!Character.isLetter(stringToCheck.charAt(i)) &&
|
|
||||||
!Character.isDigit(stringToCheck.charAt(i))) {
|
|
||||||
score++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience method for returning the count of numbers in a given String.
|
|
||||||
*
|
|
||||||
* @param stringToCheck
|
|
||||||
* @return The numbers of digits in the String
|
|
||||||
*/
|
|
||||||
protected int getNumberCount(String stringToCheck) {
|
|
||||||
int score = 0;
|
|
||||||
int loops = stringToCheck.length() - 1;
|
|
||||||
for (int i = 0; i <= loops; i++) {
|
|
||||||
if (Character.isDigit(stringToCheck.charAt(i))) {
|
|
||||||
score++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the guides to show on the view.<br />
|
|
||||||
* On the line style, the guides will show underneath<br />
|
|
||||||
* On the rounded style, the guides will be shown on the outer edges.<br />
|
|
||||||
* The view will be redrawn after the method is called.
|
|
||||||
*
|
|
||||||
* @param showGuides True if you want the guides to be shown
|
|
||||||
*/
|
|
||||||
public void setShowGuides(boolean showGuides) {
|
|
||||||
mShowGuides = showGuides;
|
|
||||||
if (mPassword != null && mPassword.length() > 0) {
|
|
||||||
generatePasswordScore();
|
|
||||||
} else {
|
|
||||||
mCurrentScore = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
invalidate();
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether the view is showing the guides for the password score
|
|
||||||
*
|
|
||||||
* @return True if the guides are being shown
|
|
||||||
*/
|
|
||||||
public boolean isShowingGuides() {
|
|
||||||
return mShowGuides;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:fillViewport="true"
|
|
||||||
android:layout_above="@+id/create_key_buttons">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingLeft="16dp"
|
|
||||||
android:paddingRight="16dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:text="@string/create_key_passphrase_text" />
|
|
||||||
|
|
||||||
<org.sufficientlysecure.keychain.ui.widget.PassphraseEditText
|
|
||||||
android:id="@+id/create_key_passphrase"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:imeOptions="actionNext"
|
|
||||||
android:inputType="textPassword"
|
|
||||||
android:hint="@string/label_passphrase"
|
|
||||||
android:ems="10"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/create_key_passphrase_again"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:inputType="textPassword"
|
|
||||||
android:hint="@string/label_passphrase_again"
|
|
||||||
android:ems="10"
|
|
||||||
android:layout_gravity="center_horizontal" />
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/create_key_show_passphrase"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:text="@string/label_show_passphrase" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:background="?attr/colorButtonRow"
|
|
||||||
android:id="@+id/create_key_buttons">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/create_key_back_button"
|
|
||||||
android:paddingLeft="16dp"
|
|
||||||
android:paddingRight="16dp"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@string/btn_back"
|
|
||||||
android:textAllCaps="true"
|
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
|
||||||
android:drawableLeft="@drawable/ic_chevron_left_grey_24dp"
|
|
||||||
android:drawablePadding="8dp"
|
|
||||||
android:gravity="left|center_vertical"
|
|
||||||
android:clickable="true"
|
|
||||||
style="?android:attr/borderlessButtonStyle" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/create_key_next_button"
|
|
||||||
android:paddingLeft="16dp"
|
|
||||||
android:paddingRight="16dp"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@string/btn_next"
|
|
||||||
android:textAllCaps="true"
|
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
|
||||||
android:drawableRight="@drawable/ic_chevron_right_grey_24dp"
|
|
||||||
android:drawablePadding="8dp"
|
|
||||||
android:gravity="right|center_vertical"
|
|
||||||
android:clickable="true"
|
|
||||||
style="?android:attr/borderlessButtonStyle" />
|
|
||||||
</LinearLayout>
|
|
||||||
</RelativeLayout>
|
|
||||||
@@ -15,36 +15,17 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/label_no_passphrase" />
|
android:text="@string/label_no_passphrase" />
|
||||||
|
|
||||||
<FrameLayout
|
<EditText
|
||||||
|
android:id="@+id/passphrase_passphrase"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginBottom="8dp">
|
android:layout_marginBottom="8dp"
|
||||||
|
android:imeOptions="actionNext"
|
||||||
<org.sufficientlysecure.keychain.ui.widget.PassphraseEditText
|
android:hint="@string/label_passphrase"
|
||||||
android:id="@+id/passphrase_passphrase"
|
android:inputType="textPassword"
|
||||||
android:layout_width="match_parent"
|
android:ems="10"
|
||||||
android:layout_height="wrap_content"
|
android:layout_gravity="center_horizontal" />
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:imeOptions="actionNext"
|
|
||||||
android:hint="@string/label_passphrase"
|
|
||||||
android:inputType="textPassword"
|
|
||||||
android:ems="10"
|
|
||||||
android:layout_gravity="center_horizontal" />
|
|
||||||
|
|
||||||
<org.sufficientlysecure.keychain.ui.widget.PasswordStrengthBarView
|
|
||||||
android:id="@+id/passphrase_repeat_passphrase_strength"
|
|
||||||
android:layout_width="48dp"
|
|
||||||
android:layout_height="8dp"
|
|
||||||
android:layout_gravity="end|center_vertical"
|
|
||||||
custom:strength="medium"
|
|
||||||
custom:showGuides="false"
|
|
||||||
custom:color_fail="@color/password_strength_low"
|
|
||||||
custom:color_weak="@color/password_strength_medium"
|
|
||||||
custom:color_strong="@color/password_strength_high" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/passphrase_passphrase_again"
|
android:id="@+id/passphrase_passphrase_again"
|
||||||
|
|||||||
@@ -11,20 +11,6 @@
|
|||||||
<attr name="initializeFolded" format="boolean" />
|
<attr name="initializeFolded" format="boolean" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<!-- Taken from Matt Allen Password Strength View
|
|
||||||
https://github.com/matt-allen/android-password-strength-indicator -->
|
|
||||||
<declare-styleable name="PasswordStrengthView">
|
|
||||||
<attr name="strength" format="enum">
|
|
||||||
<enum name="weak" value="0" />
|
|
||||||
<enum name="medium" value="1" />
|
|
||||||
<enum name="strong" value="2" />
|
|
||||||
</attr>
|
|
||||||
<attr name="showGuides" format="boolean" />
|
|
||||||
<attr name="color_fail" format="color" />
|
|
||||||
<attr name="color_weak" format="color" />
|
|
||||||
<attr name="color_strong" format="color" />
|
|
||||||
</declare-styleable>
|
|
||||||
|
|
||||||
<declare-styleable name="PrefixedEditText">
|
<declare-styleable name="PrefixedEditText">
|
||||||
<attr name="prefix" format="string" />
|
<attr name="prefix" format="string" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|||||||
Reference in New Issue
Block a user