Results 1 to 12 of 12
- 01-07-2011, 04:53 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
Who can improvise this validation method?
I want to check the strength of password.I did this simple boolean method.However i found out that i always assume user to input alpha.so if they enter 6 digits password strength is strong too.How to improvise this so that i can check there is a mixture of digit and alpha in it?Thanks
public static boolean checkStrength(String pass){
boolean strong =false;
boolean goodLength = false;
boolean mix = false;
if(pass.length() >= 6) {
goodLength = true;
for(int i=0;i<=pass.length();i++) {
if(pass.contains(Integer.toString(i))) {
mix = true;
}
}
if(mix && goodLength){
strong = true;
}
}
return strong;
}
- 01-07-2011, 05:06 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
The Character class (with all its utility methods) can be of help here; parse the potential password as follows:
You decide what is and what isn't a good/strong password given the three ints letter, digit and other.Java Code:int letter= 0, digit= 0, other= 0; for (int i= 0; i < pass.length(); i++) { char c= pass.charAt(i); if (Character.isLetter(c)) letter++; else if (Character.isDigit(c)) digit++; else other++; }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-08-2011, 12:34 AM #3
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
wow, counting character by character, that's genius.
@OP, you don't have to check and count character by character. There are already basic String methods like matches() to check for patterns. If you only want to see if there are mixture of digits and alphabets only,
Java Code:if ( pass.matches(".*[0-9]+.*") && pass.matches(".*[a-zA-Z]+.*") ){ System.out.println("Good mixture"); }else{ System.out.println("No good mixture"); }Last edited by JavaHater; 01-08-2011 at 12:44 AM.
- 01-08-2011, 07:31 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
I'm out of this forum because of that JavaHater youngster. This is no fun anymore.
JosLast edited by JosAH; 01-08-2011 at 07:52 AM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-08-2011, 08:15 AM #5
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
This shows you couldn't take any criticism. If you want to reply to posts, be prepared to take criticisms. Just like when you criticised my methods, I am prepared and have always stand my ground. your method of iterating character by character to find the pattern is indeed the "long-winded" way. Its like teaching C to unsuspecting Java newbies (i wonder what will happen if they used your methods outside in real working life). Hence, my comments.
If you think you are right, stand your ground and explain why your method is ok and should be used ( in academic and outside). Turning tails is not the answer.
- 01-08-2011, 10:32 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
My method uses only O(n) steps (exactly) where n is the length of the String. I don't think the OP understands (convoluted) use of regular expressions yet so I didn't mention them. You were just trying to be a smart ass while down talking on my reply and supplying a spoonfeeding (convoluted) example which you edited later. You have a bad character and (imho) you don't belong in this forum. I asked for your immediate ban or I'm out of here; I want to have a bit of fun (and honest criticism from other posters) no sarcastic hostile remarks from some youngster who thinks he knows everything. You should read Henry Weinberg's "Egoless Programming".
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-08-2011, 11:04 AM #7
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
and i don't think OP understand optimization (premature) as yet. Beside, you have to convert each character of the string to char before you can use Character methods, plus declare a whole lot of other variables.
Wrong, I am supplying an suggestion that contains a widely used mechanism (regex).You were just trying to be a smart ass while down talking on my reply and supplying a spoonfeeding (convoluted) example which you edited later.
Besides, string operations are so damn common that its crazy not to learn about the various methods Java can provide. If OP is not going to learn now in school, then when? Out in the working world? Imagine when the interviewer ask OP to write a regular expression, what would he say? errmm "JosAH only shows me how to do it character by character...so.... "
so are you. Remember, it takes 2 hands to clap. There is always a cause and effect.You have a bad character and (imho) you don't belong in this forum.
My criticisms are honest enough. Your character by character iteration method to check for things (in this thread) is a lesser used method when you have a programming language like Java that provides better methods for handling such things. I did not say that you cannot teach OP how to use it. I only say that OP don't need to use such a method. The moderators/admin will have eyes to see and the mind to think. So far, I have not provided ridiculous answers that are way out of topic. every one of them tries to resolve OP's question. Why would they ban me because you say so?(and you have no reason to "threaten" the admins like that. you are being rude.)I asked for your immediate ban or I'm out of here; I want to have a bit of fun (and honest criticism from other posters)
in the end, you just have an ego. You can't put down that ego when someone points out something unfavourable and couldn't humbly accept the fact. I guess its because you think you are older than me and that everything you say is right, huh?no sarcastic hostile remarks from some youngster who thinks he knows everything. You should read Henry Weinberg's "Egoless Programming".
Jos
Finally, I don't care if you don't come back or not. I will not be the cause of that. You can just ignore my posts next time and continue to give advice as always , nobody is forcing you to read my posts. If you can think like that, everything should be fine, there's no reason to leave because you are not fine with me.
- 01-08-2011, 11:41 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
There is no 'conversion' needed; primitive char values are taken from a String, that's all. Slurping in an entire regexp class (or more) is way more expensive.
The OP is obviously just starting; if s/he's on his/her right way s/he'll learn about regular expressions later. There is no need to show off and supply a boiler plate convoluted solution now (as you did again). But what do you care? (as you said yourself) In some idiotic way you enjoy ruining a nice forum.
Because you're ruining a nice forum that uses the 'strategy' of not supplying boilerplate code; but what do you care? I've seen more egotistical know-it-alls like you before. They come and go but they always try to outsmart other people for no reason in the ICT industry. And indeed, I've been in it longer than you and I've seen more idiots like you. I don't treaten admins, I've made up my mind and drawn my conclusion: you have to be banned from this forum because you ruin the atmosphere here with your pre-cooked, convoluted boilerplate code. Better do that elsewhere and tell people about it so can avoid those places.
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-08-2011, 12:02 PM #9
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
i am talking about those needless for loop, those extra variables declared, those needless if/else statements . those calling of String method charAt(i) for EACH iteration, etc. The OP doesn't need to learn about such "optimizations" that you are talking about ( which i doubt its faster than a regex without actually doing a benchmark) or write such "tedious" code. What he needs to learn about is methods that will help him tremendously and be of use now and in the future.
later? when? You don't dictate anything here, because you are not his/her teacher or his/her parents who say "you must do this , you must do that. Today you do this, tomorrow you that.blah blah". He is free to learn himself...and so he came here , to learn about different methods to do things. What's so wrong with that.? The forum doesn't just cater to you only. There are many others who view the forum , finding solutions and such etc, you do know that right?The OP is obviously just starting; if s/he's on his/her right way s/he'll learn about regular expressions later.
I will only have no problem with your comment on my solution being "convoluted", IF you can show me a better way of doing it. Otherwise, its just bull you are yapping.There is no need to show off and supply a boiler plate convoluted solution now (as you did again). But what do you care? (as you said yourself)
show off ? you mean you consider people providing legitimate and proven methods of solving the problems as a show off? what logic is that?
First occurrence of the word "idiot" , now, who's being rude ?In some idiotic way you enjoy ruining a nice forum.
wrong, I don't supply the answer to YOU. Why do you think that I am "out-smarting" anyone? Just because you don't see eye to eye with my solution, doesn't mean I am wrong. YOU are not the student. The choice is up to OP to choose your solution or mine. And, the forum doesn't forbid posting examples. There is no rules to say "Posting full solutions or examples to the OP will result in a ban". So , until it does, just suck it up.Because you're ruining a nice forum that uses the 'strategy' of not supplying boilerplate code; but what do you care? I've seen more egotistical know-it-alls like you before. They come and go but they always try to outsmart other people for no reason in the ICT industry.
Now, I see the word "idiot" a 2nd time. You should be the one to be banned for being ultra rude. Should i report you? I will give you a chance to apologize, before the admin finds a negative point about you and decide to ban you instead. the admins have the eyes to see and the mind to think, you know.And indeed, I've been in it longer than you and I've seen more idiots like you. I don't treaten admins, I've made up my mind and drawn my conclusion: you have to be banned from this forum because you ruin the atmosphere here with your pre-cooked, convoluted boilerplate code. Better do that elsewhere and tell people about it so can avoid those places.
Jos
- 01-08-2011, 12:13 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-08-2011, 01:10 PM #11
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
i will let you off this time for calling me "idiot" 2 times in this thread with no apologies whatsoever. There will strictly not be a next time. You will be reported if this occurs again.
- 01-08-2011, 01:22 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Validation of Email
By GreatWall in forum Web FrameworksReplies: 5Last Post: 09-26-2010, 11:13 AM -
which type is a good validation method in struts2
By javastuden in forum Java ServletReplies: 2Last Post: 07-13-2010, 01:25 PM -
VAlidation
By chetna1982 in forum New To JavaReplies: 2Last Post: 12-11-2008, 07:08 AM -
Help in adding some validation..
By tornado in forum New To JavaReplies: 5Last Post: 11-30-2008, 01:36 AM -
Input Validation
By kickflipper1087 in forum New To JavaReplies: 5Last Post: 11-03-2008, 05:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks