topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 1:49 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - simsim00 [ switch to compact view ]

Pages: [1]
1
well, i have written this code for the problem give below. Plz help me to bring high quality to this i.e use of Hungarian Notation and commnts as required in the problem given below:
Problem:
Writing a maintainable code makes the product with High Quality. Here you are given a scenario where you have to write a maintainable code for the given problem.

Scenario:


Virtual Solutions is an IT solution provider company. It has hired you as a Software Engineer. Your job is to write code, but at the same it should be of High Quality.  Your Team Lead has asked you to write a very small code of user login functionality. The code should be of High Quality.

You are required to

a.   Write correct code for the user login in Java or C++
b.   Make use of Hungarian Notation for coding purpose
c.   Make use of Comments in the Code where required necessary.


code

<html>
<head>
<title>Khalid Mahmood   </title>
</head>

<body>
<br>
 <p> <h3><center>Please enter your user name and
 password</center></h3></p>

 <br>
 <br>
 <form  action="process2.jsp "    method = "post" >
 <center>username</center>
 <center><input type = "text" name=
 "username"></center>
 <center>password</center>
 <center><input type = "password" name =
 "password"></center>
 <center><input type="submit"     name="Submit"
 value="Login"></center>


 </form>

 </body>
 </html>








<%@ page import="java.util.*" %>
<jsp:useBean id="idHandler" class="foo.Login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>

<%
   if (idHandler.validate()) {
%>
<jsp:forward page="success.jsp"/>
<%
   }  else {
%>
<jsp:forward page="retry.jsp"/>
<%
   }
%>












package foo;
 import java.sql.*;

 public class Login {

   private String username = "";
 private String password = "";

   public Login() {
  }

  public void setUsername(String username) {
     this.username = username;
  }

  public void setPassword(String password) {
     this.password = password;
   }


 public boolean  authenticate(String username2,
 String password2) {
  String query="select * from Registration;";
   String DbUserName="";
   String DbPassword="";
   String finalUser="";
  try {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection
 con=DriverManager.getConnection("jdbc:odbc:register");
   Statement stat=con.createStatement();
   ResultSet rst=stat.executeQuery(query);
   while(rst.next())

  {
   DbUserName=rst.getString("UserName");

  DbPassword=rst.getString("password");

   if (username2.equals(DbUserName) &&
 password2.equals(DbPassword)) {

 break;
     }


   }
 return true;
 }catch(Exception e){

 e.printStackTrace();
 return false;
 }
}}

2
This is my C++ code for the problem given below. But since i'm newbie to java, dont know how to write equivalent Java code. If you people can help, plz do so. Helping hands are always praised worthy. Im stuck...Plz assist me..

Code for Login page in C++
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <fstream>
using std::ifstream;
#include <string>
using std::string;
string readString(ifstream&);
int main(int argc, char *argv[])
{
char user[80];
char pass[80];
string line_in;
string::size_type pos;
ifstream fp_in;
int count = 0;
string user_pass[100][2];
fp_in.open("users.txt");
if(fp_in == NULL)
{
cout << "Could not open user file, exiting." << endl;
return -1;
}
while(!fp_in.eof())
{
line_in=readString(fp_in);
if(line_in.length() > 0)
{
pos = line_in.find("\t",0);
if( pos != string::npos)
{
user_pass[count][0] = line_in.substr(0,pos);
user_pass[count][1] = line_in.substr(pos+1);
count++;
}
}
}
fp_in.close();
if(!count > 0)
{
cout << "Userlist is empty, exiting" << endl;
return -2;
}
int logged_in=0;
while(!logged_in)
{
cout << "Enter user name: ";
cin >> user;
cout << "Enter password: ";
cin >> pass;
int found = 0;
for(int x=0;x<count && !found;x++)
{
if(user_pass
  • [0].compare(user) == 0)

{
found = 1;
if(user_pass
  • [1].compare(pass) == 0)

{
found = 1;
logged_in = 1;
}
else
{
cout << "Invalid password!" << endl;
}
}
}
if(!found)
{
cout << "Invalid username!" << endl;
}
}
cout << "Logged in successfully!" << endl;
return 0;
}
string readString(ifstream& reader)
{
char buffer[256];
reader.getline(buffer,256);
string str1 = buffer;
return str1;
}

Problem:
Writing a maintainable code makes the product with High Quality. Here you are given a scenario where you have to write a maintainable code for the given problem.

Scenario:


Virtual Solutions is an IT solution provider company. It has hired you as a Software Engineer. Your job is to write code, but at the same it should be of High Quality. Your Team Lead has asked you to write a very small code of user login functionality. The code should be of High Quality.

You are required to

a. Write correct code for the user login in Java following the guidelines for writing code
b. Make use of Hungarian Notation for coding purpose

c. Make use of Comments in the Code where required necessary.

Pages: [1]