arrowHome arrow Forum Wednesday, 27 August 2008  
Main Menu
Home
Media Gallery
J2EE Blog
Forum
News
Downloads
News Feeds
FAQ's
Links
System Status
Contact Us
About iDoumo
Latest Posts
Find suspicious files abukta
Automate Filesystem Dump abukta
Add route to server abukta
Benefits of Logical Volume Management abukta
Performance Costs of using LVM abukta
Login Form
Username

Password

Remember me
Forgotten your password?
No account yet? Create one

Newsflash

Workday Devil Mountain Run draws 1,800+ runners, walkers


A pack of lean and muscular runners of many ages bolted from the starting line in downtown Danville this morning just as the sun broke through the fog.

Behind the competitive runners followed those of varying levels of proficiency, some running with strollers, others walking dogs, holding hands, or listening to music.

Threatened with cancellation just weeks ago for lack of a title sponsor, today's Workday Devil Mountain Run attracted about as many people as last year's run and likely raised even more money for Children's Hospital Oakland, organizers said.

  iDoumo Projects
  Programming
        J2EE/Java 
              Tips from J2EE Servlets & JSP class

Quick Jump To:

J2EE/Java Threads List - Search Forum
Moderated by: abukta Subscribe to this Thread
  Tips from J2EE Servlets & JSP class
  19 Jan 2006 23:06 # 1 
   abukta
 super admin
 
 profile
 
Join Date: 29 Mar 2005 21:03
Posts:
 
 Tips from J2EE Servlets & JSP class
1. For passwords, to reading to and writing from the password.properties, just use the java.util.Properties class, which is essentially a HashTable with the added capability of loading values from a properties file, and also storing values back to the properties-file using the load() and store() methods respectively. I am mentioning the relevant code-sections, in case you are stick working on those parts:

To load the password.properties file:
--------------------------------------------------------------------------------
Code:
//Below, filepath is the full path string to the password-file.

this.passwords = new Properties ();

try {
FileInputStream fis = new FileInputStream (filepath);
this.passwords.load(fis);
fis.close();

}
catch (IOException exception) {
//
throw new RuntimeException ("Password file not found, or could not be read!", exception);
}

--------------------------------------------------------------------------------

To store the passwords back to the password.properties file:

--------------------------------------------------------------------------------
Code:
try {
FileOutputStream fos = new FileOutputStream(filepath);
this.passwords.store(fos, <table width='90%' cellspacing=1 align='center' cellpadding=4><tr><td class='small'><b>Quote:</b></td></tr><tr><td class='quote'>Username/Password pairs</td></tr></table>);
}
catch (IOException exception) {
throw new RuntimeException(&quot;Password file not found, or could not be written to!&quot;,
exception);
}

--------------------------------------------------------------------------------

2. You don not need to know regular-expressions to write the validator! The class java.lang.Character has simple methods to test whether a character is a digit, and if it is aletter. (Character.isDigit(char c) and Character.isLetter(char c) ). So for example to verify that a string has only alphabetical characters, the following code would help:


--------------------------------------------------------------------------------
Code:
public boolean isAlphabeticalOnly (String string) {

char[] cbuf = string.toCharArray();

for (int i = 0; i &lt; cbuf.length; i++) {

if (!Character.isLetter(cbuf[i]))
return false;
}
return true;
}


--------------------------------------------------------------------------------

Likewise to test that a string has both alphabetical and digit characters, and also some special characters, I was expecting simply that you would re-use the AlphanumericValidator, to write something like:

-------------------------------------------------------------------------
Code:
// Three conditions must be fulfilled by the password-string:
// 1) Is not alphanumeric only, i.e. contains some special character.
// 2) Contains atleast one letter
// 3) Contains atleast one digit.


String string = (String) value;
char[] cbuf = string.toCharArray();

AlphanumericStringValidator alphanumericValidator = new
AlphanumericStringValidator();

boolean hasSpecialCharacter = ! alphanumericValidator.doValidate(string);

boolean containsDigit = false;
boolean containsLetter = false;

for (int i = 0; i &lt; cbuf.length; i++) {
if (Character.isDigit(cbuf[i]))
containsDigit = true;
if (Character.isLetter(cbuf[i]))
containsLetter = true;

}

if (hasSpecialCharacter &amp;&amp; containsDigit &amp;&amp; containsLetter) {
//valid password...

}
else {
//invalid password
}

 
message edited by abukta (19 Jan 2006 23:07)


<< Start < Prev 1 Next > End >>
Results 1 - 1 of 1



Help iDoumo

Help support "iDoumo" and free software by donating now!

Donate Once Monthly

Currency

Amount

Currency

Amount

Latest Events
There are no upcoming events currently scheduled.
View Full Calendar
Project Calendar
August 2008 September 2008
Su Mo Tu We Th Fr Sa
Week 31 1 2
Week 32 3 4 5 6 7 8 9
Week 33 10 11 12 13 14 15 16
Week 34 17 18 19 20 21 22 23
Week 35 24 25 26 27 28 29 30
Week 36 31
Media Gallery
Last update:
27 Sep, 11:53
Workday

random:

Workday
top of page

iDoumo Projects. All rights reserved.