620
Demonstrative Examples
Example 1:
Both of these examples verify a password by comparing it to a stored compressed version.
Example Language: C (Bad)
int VerifyAdmin(char *password) {
if (strcmp(compress(password), compressed_password)) {
printf("Incorrect Password!\n");
return(0);
}
printf("Entering Diagnostic Mode...\n");
return(1);
}
Example Language: Java (Bad)
int VerifyAdmin(String password) {
if (passwd.Equals(compress(password), compressed_password)) {
return(0);
}
//Diagnostic Mode
return(1);
}
Because a compression algorithm is used instead of a one way hashing algorithm, an attacker can
recover compressed passwords stored in the database.
Example 2:
The following examples show a portion of properties and configuration files for Java and ASP.NET
applications. The files include username and password information but they are stored in cleartext.
This Java example shows a properties file with a cleartext username / password pair.
Example Language: Java (Bad)
# Java Web App ResourceBundle properties file
...
webapp.ldap.username=secretUsername
webapp.ldap.password=secretPassword
...
The following example shows a portion of a configuration file for an ASP.Net application. This
configuration file includes username and password information for a connection to a database but
the pair is stored in cleartext.
Example Language: ASP.NET (Bad)
...
<connectionStrings>
<add name="ud_DEV" connectionString="connectDB=uDB; uid=db2admin; pwd=password; dbalias=uDB;"
providerName="System.Data.Odbc" />
</connectionStrings>
...
Username and password information should not be included in a configuration file or a properties
file in cleartext as this will allow anyone who can read the file access to the resource. If possible,
encrypt this information.
Observed Examples
CWE Version 4.14
CWE-258: Empty Password in Configuration File
CWE-258: Empty Password in Configuration File