Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,217,873 members, 8,035,703 topics. Date: Monday, 23 December 2024 at 06:17 PM

Challenge: Strong Password Filter - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Challenge: Strong Password Filter (1416 Views)

The Greatest Programmer On Nairaland / Blackberry 10 Picture Password For Android / Simple Code Challenge: C#, Java, C, C++ (2) (3) (4)

(1) (Reply) (Go Down)

Challenge: Strong Password Filter by kodewrita(m): 2:28pm On Apr 16, 2013
The challenge is simple and familiar. No time limit involved. participation only if it tickles your fancy. I would hope we would also try to find loopholes where we can.


Challenge: Write a program in any language that takes in a string and checks to see that it is a strong password that follows the following instructions:

---mixture of capitalized and small letters.
---numbers must be there.
---special characters in the following list( +,&,@) {just trying to make it simpler for everyone}
---no spaces

Only restriction: No COBOL. No Smalltalk and definitely no Assembler ( spare our brains grin )<--Feel free to break this.
Re: Challenge: Strong Password Filter by adexsimply(m): 2:40pm On Apr 16, 2013
cool..am on it
Re: Challenge: Strong Password Filter by ciphoenix: 5:11pm On Apr 16, 2013
kodewrita: The challenge is simple and familiar. No time limit involved. participation only if it tickles your fancy. I would hope we would also try to find loopholes where we can.


Challenge: Write a program in any language that takes in a string and checks to see that it is a strong password that follows the following instructions:

---mixture of capitalized and small letters.
---numbers must be there.
---special characters in the following list( +,&,@) {just trying to make it simpler for everyone}
---no spaces

Only restriction: No COBOL. No Smalltalk and definitely no Assembler ( spare our brains grin )<--Feel free to break this.
embarassed
Re: Challenge: Strong Password Filter by ciphoenix: 6:39pm On Apr 16, 2013
My Solution, picked up C# today tongue

http://ideone.com/LGUhC1

1 Like

Re: Challenge: Strong Password Filter by omotodun1(m): 8:04am On Apr 17, 2013
Javascript

function isStrongPassword(password) {
var m = "", i,
regex = [
[/[a-z]+/, 'at least one lowercase alphabet'],
[/[A-Z]+/, 'at least one uppercase alphabet'],
[/[+&@]+/, "at least one of the characters '+', '&', and '@'"],
[/[0-9]+/, 'at least one decimal'],
[/^[^\s]+$/, 'no space character']
]

for (i in regex)
if (!regex[i][0].test(password))
m += 'Must contain ' + regex[i][1] + ".\n";

m == "" ? alert ('Your password is strong.') : alert (m);
}

2 Likes

Re: Challenge: Strong Password Filter by Nobody: 2:38pm On Apr 17, 2013
PHP

<?php

function checkPassword($password){

if(!preg_match("#[a-z]+#", $password)){
$error .= "Password must have at least one small letter <br>";
}
if(!preg_match("#[A-Z]+#", $password)){
$error .= "Password must have at least one capital letter <br>";
}
if(!preg_match("#[0-9]+#", $password)){
$error .= "Password must have atleast one number <br>";
}
if(!preg_match("#[+&@]+#", $password)){
$error .= "Password must have any of this symbols: +,&,@ <br>";
}
if(strpos($password, ' ')){
$error .= "Password must NOT have any space character <br>";
}
if($error){
$message = $error;
}else{
$message = "Your Password is Strong!!";
}
return $message;
}
?>

1 Like

Re: Challenge: Strong Password Filter by Nobody: 4:15pm On Apr 17, 2013
ọmọ_τó_dùn:
Javascript

function isStrongPassword(password) {
var m = "", i,
regex = [
[/[a-z]+/, 'at least one lowercase alphabet'],
[/[A-Z]+/, 'at least one uppercase alphabet'],
[/[+&@]+/, "at least one of the characters '+', '&', and '@'"],
[/[0-9]+/, 'at least one decimal'],
[/^[^\s]+$/, 'no space character']
]

for (i in regex)
if (!regex[i][0].test(password))
m += 'Must contain ' + regex[i][1] + ".\n";

m == "" ? alert ('Your password is strong.') : alert (m);
}

mehn got to admit i love the way you simplified it,I was already thinking of something too complicated, nice one bro
Re: Challenge: Strong Password Filter by lordZOUGA(m): 4:29pm On Apr 17, 2013
regex.. damn..
Re: Challenge: Strong Password Filter by lordZOUGA(m): 4:37pm On Apr 17, 2013
the regex solution is beautiful but it is quite possible that a custom function written to locate the given characters. can execute faster than the regex solution
Re: Challenge: Strong Password Filter by omotodun1(m): 5:22pm On Apr 17, 2013
^
I can't argue with that. I probably sacrificed efficiency for elegance.
Re: Challenge: Strong Password Filter by omotodun1(m): 5:27pm On Apr 17, 2013
pc guru:

mehn got to admit i love the way you simplified it,I was already thinking of something too complicated, nice one bro

Thank you.
Re: Challenge: Strong Password Filter by jacob05(m): 6:45pm On Apr 17, 2013
OOP in PHP...


<?php

interface IPasswordChecker {

function check($password);
}

class UppercasePasswordCheck implements IPasswordChecker {
public function check($password){
if(!preg_match("/[A-Z]+/", $password)){
return "Your password must have at least one capital letter";
}
}
}

class LowercasePasswordCheck implements IPasswordChecker {
public function check($password){
if(!preg_match("/[a-z]+/", $password)){
return "Password must have at least one small letter";
}
}
}

class NumericPasswordCheck implements IPasswordChecker {
public function check($password){
if(!preg_match("/[0-9]+/", $password)){
return "Password must have at least one number";
}
}
}

class SymbolPasswordCheck implements IPasswordChecker {
public function check($password){
if(!preg_match("/[+&@]+/", $password)){
return "Password must have any of this symbols: +,&,@";
}
}
}

class SpacePasswordCheck implements IPasswordChecker {
public function check($password){
if(strpos($password, ' ')){
return "Password must NOT have any space character";
}
}
}

class StrongPasswordChecker implements IPasswordChecker {

private $checks = array();


function __construct() {
$this->checks[] = new UppercasePasswordCheck();
$this->checks[] = new LowercasePasswordCheck();
$this->checks[] = new SpacePasswordCheck();
$this->checks[] = new SymbolPasswordCheck();
$this->checks[] = new NumericPasswordCheck();

}
public function check($password) {
$error = "";
foreach($this->checks as $key => $check){
$error .= !($result=$check->check($password)) ? "" : $result. "<br />";
}
return $error;
}
}

$Checker = new StrongPasswordChecker();
echo $Checker->check("Pyjac"wink;

1 Like

(1) (Reply)

1000+ Beginner Programming Projects & Practice Problems / JAVA Gurus, Check This Little Code!!!! / Swapspace

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 42
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.