I have 2 problems:


First one is I want to put an user name password in a form...I have designed the table and database and I'm fetching the user names from a table and putting them in a combo box, from the combobox i select the required user name to be selected and then enter the password into a text box,if the password matches the one in the database for the required user,then it goes to the other form.
I've completed the data entry part and have used a dataset to do so.
Please guide me so as i can check if the password value in the database is same as the one entered in the text box.


My second problem is that I have to add a printing option in my software to prepare a bill...I have no idea how to print apart from facts that either crystal report or a dos printing system can be used.Please help me in any way possible about the printing.
Is data entry into a database needed for printing or just data showing currently in a form enough for printing?
Thank you for your help. :)

>Please guide me so as i can check if the password value in
>the database is same as the one entered in the text box.

Send the one entered in the text box to a stored procedure which checks for matches against the selected user.

>I have no idea how to print
Booya.

Printing is more complex than just saying "Please print my form." You need to hit the text books. Short form - create a System.Drawing.Printing.PrintDocument instance. You handle the PrintPage, BeginPrint, PrintPage, and EndPrint events to create the print image and send it to the printer.
Huh? Wha? Again, hit the text books.

Passwords in a database in clear text is a bad idea, some encryption method should be used. The simplest method is to define a binary(16) password and store the MD5 conversion of the password. You'll never decrypt the password so the user will have to have a way of resetting his password if he forgets.
The alternate is to use an encrypt/decrypt method using a fixed password (Not a good method.) or the user's password (Anything encrypted using the user's password is lost for good if the password is lost.)
If you go with the MD5 method, you might want to encrypt other sensitive data using both the fixed password and the MD5 saved value as a combination.

>Passwords in a database in clear text is a bad idea
Nice unwarranted assumption. The OP didn't mention either way whether the passwords are encrypted or not, and that information wouldn't be pertinent to the question anyway. Your post seems rather condescending.

Edited 6 Years Ago by Narue: n/a

Putting clear text passwords in databases is a newbie security mistake. The original text sounded like it was from a newbie. I didn't intend to sound condescending, thought it might be of interest to someone just starting out to also think about how secure their information is. They always have the right to say nothing, tell me "Don't teach your grandmother how to suck eggs!" or "Thanks for the input."

My from is something like a log in form as i mentioned...so obviously when i type in my password it is going to be in * and the actual characters are not being shown. The user does not get database handling authorities.
And I'm not allowed to use stored procedures, I'll have to code this part using basic c# coding methods...
Thank You for your help. :)

Solved the first one...can someone please help me out with the printing part?
Thank You. :)

Printing is more complex than just saying "Please print my form." You need to hit the text books. Short form - create a System.Drawing.Printing.PrintDocument instance. You handle the PrintPage, BeginPrint, PrintPage, and EndPrint events to create the print image and send it to the printer.
Huh? Wha? Again, hit the text books.

Well, have you looked up the above print document object? Have you looked up these events? Do you understand what they tell you?

PS "hit the text books" could include reading on-line help. It is much more helpful (to me) to buy a text book and see good examples.

PS "hit the text books" could include reading on-line help. It is much more helpful (to me) to buy a text book and see good examples.

Actually i did hit the net for search on printing....could not find anything suiting me or was not good enough to understand what they said.
If u may,please send me the link to a page which might help me understand printing.
Thank you for the help. :)

This is a modified version of the "about PrintDocument" example in the VS help. I couldn't find anything that told me the graphical width of a character. If you don't modify it, any line longer than the width of the page will disappear off the edge of the page. It will disappear off the bottom of the page if one line is long enough to extend past the end of the page unless you modify it further.
It's also modified to include all the using statements you may not need, but I did.
Anyway printing isn't easy, you have to think in graphical terms while producing your printout.
Also fix the ("C:\\...\\My Documents\\Example.txt"); line to point to the real text file to be printed.

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
public class PrintingExample : System.Windows.Forms.Form 
{
    #region types
    private System.ComponentModel.Container components;
    private System.Windows.Forms.Button printButton;
    private Font printFont;
    private StreamReader streamToPrint;
    #endregion
    public PrintingExample() : base() 
   {
      // The Windows Forms Designer requires the following call.
      InitializeComponent();
   }
   // The Click event is raised when the user clicks the Print button.
   private void printButton_Click(object sender, EventArgs e) 
   {
      try 
      {
          streamToPrint = new StreamReader
             ("C:\\...\\My Documents\\Example.txt");
          try 
          {
             printFont = new Font("Courier New", 10);
             PrintDocument pd = new PrintDocument();
             pd.PrintPage += new PrintPageEventHandler
                (this.pd_PrintPage);
             pd.Print();
          }  
          finally 
          {
             streamToPrint.Close();
          }
      }  
      catch(Exception ex) 
      {
          MessageBox.Show(ex.Message);
      }
   }
   // The PrintPage event is raised for each page to be printed.
   private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
   {
      float yPos = 0;
      int count = 0;
      float leftMargin = ev.MarginBounds.Left;
      float topMargin = ev.MarginBounds.Top;
      string line = null;

      // Calculate the number of lines per page.
      float lineHt = printFont.GetHeight(ev.Graphics);
      float linesPerPage = ev.MarginBounds.Height / lineHt;
         

      // Print each line of the file.
      while(count < linesPerPage && 
         ((line=streamToPrint.ReadLine()) != null)) 
      {
          int i1 = line.IndexOf(" ");
          while (line.Length > 75)
          {
              int i2 = line.IndexOf(" ", i1 + 1);
              while (i2 > 0 && i2 < 76)
              {
                  i1 = i2;
                  i2 = line.IndexOf(" ", i1 + 1);
              }
              if (i1 > 0 && i1 < 76)
              {
                  yPos = topMargin + (count * lineHt);
                  ev.Graphics.DrawString(line.Substring(0, i1), printFont, Brushes.Black,
                     leftMargin, yPos, new StringFormat());
                  count++;
                  line = line.Substring(i1 + 1);
                  i1 = line.IndexOf(" ");
              }
              else
              {
                  yPos = topMargin + (count * lineHt);
                  ev.Graphics.DrawString(line.Substring(0, 75), printFont, Brushes.Black,
                      leftMargin, yPos, new StringFormat());
                  count++;
                  line = line.Substring(75);
                  i1 = line.IndexOf(" ");
              }
          }
          yPos = topMargin + (count * lineHt);
          ev.Graphics.DrawString(line, printFont, Brushes.Black, 
             leftMargin, yPos, new StringFormat());
          count++;
      }

      // If more lines exist, print another page.
      if(line != null)
         ev.HasMorePages = true;
      else
         ev.HasMorePages = false;
   }
   // The Windows Forms Designer requires the following procedure.
   private void InitializeComponent() 
   {
      this.components = new System.ComponentModel.Container();
      this.printButton = new System.Windows.Forms.Button();

      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(504, 381);
      this.Text = "Print Example";

      printButton.ImageAlign = 
         System.Drawing.ContentAlignment.MiddleLeft;
      printButton.Location = new System.Drawing.Point(32, 110);
      printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
      printButton.TabIndex = 0;
      printButton.Text = "Print the file.";
      printButton.Size = new System.Drawing.Size(136, 40);
      printButton.Click += new System.EventHandler(printButton_Click);

      this.Controls.Add(printButton);
   }
   // This is the main entry point for the application.
   public static void Main(string[] args) 
   {
      Application.Run(new PrintingExample());
   }
}
This article has been dead for over six months. Start a new discussion instead.