Results 1 to 12 of 12
  1. #1
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default 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;
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default

    The Character class (with all its utility methods) can be of help here; parse the potential password as follows:

    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++;
    }
    You decide what is and what isn't a good/strong password given the three ints letter, digit and other.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    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.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default

    I'm out of this forum because of that JavaHater youngster. This is no fun anymore.

    Jos
    Last edited by JosAH; 01-08-2011 at 07:52 AM.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by JosAH View Post
    I'm out of this forum because of that JavaHater youngster. This is no fun anymore.

    Jos
    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.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JavaHater View Post
    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.
    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".

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by JosAH View Post
    My method uses only O(n) steps (exactly) where n is the length of the String.
    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.

    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.
    Wrong, I am supplying an suggestion that contains a widely used mechanism (regex).
    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.... "

    You have a bad character and (imho) you don't belong in this forum.
    so are you. Remember, it takes 2 hands to clap. There is always a cause and effect.

    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)
    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.)

    no sarcastic hostile remarks from some youngster who thinks he knows everything. You should read Henry Weinberg's "Egoless Programming".
    Jos
    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?


    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.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JavaHater View Post
    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.
    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.

    Quote Originally Posted by JavaHater View Post
    Wrong, I am supplying an suggestion that contains a widely used mechanism (regex).
    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.... "
    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.


    Quote Originally Posted by JavaHater View Post
    Why would they ban me because you say so?(and you have no reason to "threaten" the admins like that. you are being rude.)
    Finally, I don't care if you don't come back or not. I will not be the cause of that.
    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.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by JosAH View Post
    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.
    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.

    The OP is obviously just starting; if s/he's on his/her right way s/he'll learn about regular expressions later.
    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?

    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)
    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.
    show off ? you mean you consider people providing legitimate and proven methods of solving the problems as a show off? what logic is that?

    In some idiotic way you enjoy ruining a nice forum.
    First occurrence of the word "idiot" , now, who's being rude ?

    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.
    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.

    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
    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.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JavaHater View Post
    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.
    All I can hope for is that you'll be banned from here asap. I'm sick and tired of types like you; you add no positive value here despite your pseudo clever remarks in which you're trying to weasle yourself out of the responsibility of your own deeds. Goodbye.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    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.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JavaHater View Post
    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.
    All I can (and want) to do is repeat my previous reply:

    Quote Originally Posted by JosAH
    All I can hope for is that you'll be banned from here asap. I'm sick and tired of types like you; you add no positive value here despite your pseudo clever remarks in which you're trying to weasle yourself out of the responsibility of your own deeds. Goodbye.
    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Validation of Email
    By GreatWall in forum Web Frameworks
    Replies: 5
    Last Post: 09-26-2010, 11:13 AM
  2. which type is a good validation method in struts2
    By javastuden in forum Java Servlet
    Replies: 2
    Last Post: 07-13-2010, 01:25 PM
  3. VAlidation
    By chetna1982 in forum New To Java
    Replies: 2
    Last Post: 12-11-2008, 07:08 AM
  4. Help in adding some validation..
    By tornado in forum New To Java
    Replies: 5
    Last Post: 11-30-2008, 01:36 AM
  5. Input Validation
    By kickflipper1087 in forum New To Java
    Replies: 5
    Last Post: 11-03-2008, 05:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •