Thursday, April 30, 2015

Class Reader Diagram

Here is the class diagram we did in class.

CardReader is an abstract class that cannot be instantiated except through its children.It containst all the fields and methods that are common to the busreaders--that is methods which have the same implementation.

TrainCardReader and BusCardReader inherit from CardReader.

CardReader has an aggregation relationship to Card. The CardReader class contains an instance of the Card Class, but the Card class has an existence separate from the container.

Card aggregates Trip (as do the readers)

TrainCardReader and BusCardReader implement the interface IReader which means they must provide a body for its abstract methods

Assignment 3 class Example

Here is the Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Login</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr>
            <td>Enter User Name</td>
            <td>
                <asp:TextBox ID="txtUserName" runat="server">
</asp:TextBox></td>
        </tr>
            <tr>
            <td>Enter Password</td>
            <td>
                <asp:TextBox ID="txtPassword" runat="server">
</asp:TextBox></td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnSubmint" runat="server" Text="Log in" 
OnClick="btnSubmint_Click" /></td>
            <td>
                <asp:Label ID="lblResult" runat="server" Text="">
</asp:Label></td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html>


Here is the Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmint_Click(object sender, EventArgs e)
    {
        LoginClass lc = new LoginClass(txtPassword.Text, txtUserName.Text);
        int result = lc.ValidateLogin();
        if (result != 0)
        {
            
            Session["userKey"] = result;
            Response.Redirect("Welcome.aspx");
        }
        else
        {
            lblResult.Text = "Invalid login";
        }
    }
}

Here is the ReviewerRegistration.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Login</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr>
            <td>Enter User Name</td>
            <td>
                <asp:TextBox ID="txtUserName" runat="server">
</asp:TextBox></td>
        </tr>
            <tr><%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReviewerRegistration.aspx.cs" Inherits="ReviewerRegistration" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr>
            <td>First Name</td>
            <td><asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox></td>
        </tr>
         <tr>
            <td>Last Name</td>
            <td><asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
        </tr>
         <tr>
            <td>Email</td>
            <td><asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
        </tr>
         <tr>
            <td>User Name</td>
            <td><asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td>
        </tr>
         <tr>
            <td>Password</td>
            <td><asp:TextBox ID="txtPassword" runat="server"  TextMode="Password"></asp:TextBox></td>
        </tr>
         <tr>
            <td>Confirm Password</td>
            <td><asp:TextBox ID="txtConfirm" runat="server" TextMode="Password"></asp:TextBox></td>
        </tr>
         <tr>
            <td>
                <asp:Button ID="btnRegister" runat="server" Text="Register" OnClick="btnRegister_Click" /></td>
            <td>
                <asp:Label ID="lblErrorSuccess" runat="server" Text=""></asp:Label></td>
        </tr>
       
    </table>
        <asp:LinkButton ID="LbLogin" runat="server" 
PostBackUrl="~/Default.aspx">Log in</asp:LinkButton>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtUserName" Display="None" ErrorMessage="User name required"></asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtLastName" Display="None" ErrorMessage="Last name required"></asp:RequiredFieldValidator>
    </div>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail" Display="None" ErrorMessage="Invalid email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
    </form>
</body>
</html>

            <td>Enter Password</td>
            <td>
                <asp:TextBox ID="txtPassword" runat="server">
</asp:TextBox></td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnSubmint" runat="server" Text="Log in" 
OnClick="btnSubmint_Click" /></td>
            <td>
                <asp:Label ID="lblResult" runat="server" Text="">
</asp:Label></td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html>


And here is the ReviewerRegistration.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ReviewerRegistration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {

        BookReviewDbEntities db = new BookReviewDbEntities();
        try
        {


            Reviewer r = new Reviewer();
            r.ReviewerFirstName = txtFirstName.Text;
            r.ReviewerLastName = txtLastName.Text;
            r.ReviewerEmail = txtEmail.Text;
            r.ReviewerUserName = txtUserName.Text;
            r.ReviewPlainPassword = txtPassword.Text;

            KeyCode kc = new KeyCode();
            int code = kc.GetKeyCode();

            r.ReviewerKeyCode = code;

            PasswordHash ph = new PasswordHash();

            Byte[] hashed = ph.HashIt(txtPassword.Text, code.ToString());
            r.ReviewerHashedPass = hashed;
            r.ReviewerDateEntered = DateTime.Now;
            db.Reviewers.Add(r);

            CheckinLog log = new CheckinLog();
            log.Reviewer = r;
            log.CheckinDateTime = DateTime.Now;
            db.CheckinLogs.Add(log);
            
            db.SaveChanges();
            lblErrorSuccess.Text = "Sucessfully Registered";
        }
        catch(Exception ex)
        {
            lblErrorSuccess.Text = ex.Message;
        }
    }
}

And here again is the LoginClass.cs though it is the same as in the other blog. I am not including the password hash class or the key code classes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// 
/// This class takes in the user name and password
/// retrieves information from the database
/// and then hashes the password and key to
/// see if it matches the database hash
/// 
public class LoginClass
{
    //class level variables-fields
    private string pass;
    private string username;
    private int seed;
    private byte[] dbhash;
    private int key;
    private byte[] newHash;

    //constructor takes in password and username
    public LoginClass(string pass, string username)
    {
        this.pass = pass;
        this.username = username;
    }

    //gets the user info from the database
    private void GetUserInfo()
    {
        //declare the ADO Entities
        BookReviewDbEntities brde = new BookReviewDbEntities();
        //query the fields
        var info = from i in brde.Reviewers
                   where i.ReviewerUserName.Equals(username)
                   select new { i.ReviewerKey, i.ReviewerHashedPass, i.ReviewerKeyCode };

        //loop through the results and assign the
        //values to the field variables
        foreach (var u in info)
        {
            seed = u.ReviewerKeyCode;
            dbhash = u.ReviewerHashedPass;
            key = u.ReviewerKey;
        }
    }

    private void GetNewHash()
    {
        //get the new hash
        PasswordHash h = new PasswordHash();
        newHash = h.HashIt(pass, seed.ToString());
    }

    private bool CompareHash()
    {
        //compare the hashes
        bool goodLogin = false;

        //if the hash doesn't exist
        //because not a valid user
        //the return will be false
        if (dbhash != null)
        {
            //if the hashes do match return true
            if (newHash.SequenceEqual(dbhash))
                goodLogin = true;
        }

        return goodLogin;

    }

    public int ValidateLogin()
    {
        //call the methods
        GetUserInfo();
        GetNewHash();
        bool result = CompareHash();

        //if the result is not true
        //set the key to 0
        if (!result)
            key = 0;


        return key;
    }

}

Thursday, April 23, 2015

Activity diagrams

Here is the one with swim lanes

Tuesday, April 14, 2015

Use cases from Class

Here are the use cases for the Commuter

Here are the use cases for Card Reader


Use Case: Pay Bus Fare
Precondition: Card has sufficient funds.

Trigger: Customer Taps card on entering bus.
Steps
1. Check the Card Type 
2. Get Fare Information
3. If Card Type Purse
4. Check Card balance
5. Deduct Card Fare
a. Card type pass (alternate path)
b. Bypass fare deduction
6. Record the trip information on Card
7. Log trip information to servers
Terminal Condition:
The fare is paid and the trip is recorded

Tuesday, April 7, 2015

First ASP

the Default web page

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    
    <link href="FirstAspStyle.css" rel="stylesheet" type="text/css" />
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>Choose your birthday</p>
        <!--add an asp calendar control-->
        <asp:Calendar ID="CalendarFirst"  
             runat="server" ></asp:Calendar>
        <p>
        <asp:Label ID="Label1" runat="server" 
            Text="Enter Your Name"></asp:Label>
        <asp:TextBox ID="txtName" 
            runat="server" CssClass="textback"></asp:TextBox></p>
        <p>
        <asp:Button ID="Button1" 
            runat="server" Text="Get Days" OnClick="Button1_Click" />
        <asp:Label ID="lblResult" runat="server" 
            Text=""></asp:Label>

        </p>
    </div>
    </form>
</body>
</html>

The C# code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    /* this is a multi line
     * comment
     */


    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //take the value from the text box
        //and assign it to the variable name
        string name = txtName.Text;
        string birthDate = CalendarFirst.SelectedDate.ToShortDateString();
        lblResult.Text = "Hello, " + name + " Your birthday is " + birthDate;
      
    }
}

Here is the CSS

body {
}

table tr th{
    font-weight:bold;
    background-color:aliceblue;
    border :5px solid black;
}

.textback{
    background-color:yellow;
}