Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

FileStream

$
0
0

I want to use FileStream to register(save) account and then on next form login by checking if entered name and password are equls to the one i saved

This is Form1

tring tname = txtName.Text;
string tpass = txtPass.Text;
string temail = txtEmail.Text;
string tgender = txtGende.Text;
if ((txtName.Text != null) &&(txtPass.Text !=null) &&(txtEmail.Text != null) &&(txtGende.Text != null))
{
Box tmpBox = new Box(tname, tpass, temail, tgender);
boxes.Add(tmpBox);
lstBoxes.Items.Add(new ListViewItem(tmpBox.GetInfo()));
MessageBox.Show("Total Boxes =" + boxes.Count);
FileStream fs = new FileStream("boxes.bin", FileMode.Create);
bf.Serialize(fs, boxes);
fs.Close();

}

Form 2

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Test1
{
    public partial class Form2 : Form
    {
        private List<Box> boxes;
        private BinaryFormatter bf;
        private FileStream fs;

        public Form2()
        {
            InitializeComponent();
            boxes = new List<Box>();
        }

        private void btnLog_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream("boxes.bin", FileMode.Open, FileAccess.Read);
            try
            {
                if (txtName.Text == fs.ToString() && txtPass.Text == fs.ToString())
                {
                    Loud newLoud = new Loud();
                    newLoud.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Wrong username or password");
                }
            }
            finally
            {
                fs.Close();
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        public string fileStream { get; set; }
    }
}

           

Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>