 			else if @is_upper c then caps++
 			else if @is_lower c then lowers++
 
-		if lowers >= caps and lowers >= digits then is_lower
-		else if digits > lowers and digits >= caps then is_digit
-		else is_upper
+		if lowers >= caps and lowers >= digits then @is_lower
+		else if digits > lowers and digits >= caps then @is_digit
+		else @is_upper
 
 	add_syms: (input, n) ->
 		return input if n <= 0


config =
	pw: { min_size: 8, max_size: 16 }

is_upper = (c) -> "A".charCodeAt(0) <= c and c <= "Z".charCodeAt(0)
is_lower = (c) -> "a".charCodeAt(0) <= c and c <= "z".charCodeAt(0)
is_digit = (c) -> "0".charCodeAt(0) <= c and c <= "9".charCodeAt(0)
is_valid = (c) -> @is_upper(c) or @is_lower(c) or @is_digit (c)

class PasswdGenerator
	constructor: (@email, passphrase, itercnt) ->
		# TODO If localStorage has stored key, no need to generate again
		@_key = @derive(@email, passphrase)

	# Private function
	derive: (email, passphrase, itercnt) ->
		C.PBKDF2 passphrase, email,
			{ keySize: 512/32, iterations: itercnt, hasher: C.algo.SHA512 }


		arr.push input[last...]
		arr.join ""

	is_upper: (c) -> "A".charCodeAt(0) <= c and c <= "Z".charCodeAt(0)
	is_lower: (c) -> "a".charCodeAt(0) <= c and c <= "z".charCodeAt(0)
	is_digit: (c) -> "0".charCodeAt(0) <= c and c <= "9".charCodeAt(0)
	is_valid: (c) -> @is_upper(c) or @is_lower(c) or @is_digit (c)

window.PasswdGenerator = PasswdGenerator
