Click here to Skip to main content
11,412,578 members (74,530 online)
Click here to Skip to main content
Add your own
alternative version

Password Safe Reader for Windows Mobile

, , , , 20 Mar 2010 GPL3
A Windows Mobile C# reader for the popular Password Safe archive files.
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Axantum;
using Axantum.PasswordSafe;
using Microsoft.Win32;
using System.Security.Permissions;
using System.Security;
using PwSP;



namespace PwSP
{
  
    public partial class frm_Main : Form
    {
        public frm_Main()
        {
            InitializeComponent();
        }
        string str_File_Password = "";

        private void btn_Open_File_Click(object sender, EventArgs e)
        {
            //if (openFileDialog1.ShowDialog() == DialogResult.OK)
          //  {
            Stream pwsafeStream = new FileStream("My Documents\\pass.psafe3", FileMode.Open, FileAccess.Read);              
//                Stream pwsafeStream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                //List<object> Groups = new List<object>(30);
                using (PasswordSafeReader pass_reader = new PasswordSafeReader(pwsafeStream))
                {
                    try
                    {
                        pass_reader.SetPassphrase(str_File_Password);
                    }
                    catch (Exception ex)
                    {
                        menuItem3_Click(null, null);
                    }
                    
                    while (pass_reader.Read())
                    {
                        switch (pass_reader.CurrentPartType)
                        {
                            case PasswordSafePartType.Header:
                                PasswordSafeHeader header = pass_reader.Header;
                                break;
                            case PasswordSafePartType.Record:
                                PasswordSafeRecord record = pass_reader.Record;
                                string str_Record_Group=record.Group;
                                ds_Passwords.tbl_Passwords.Addtbl_PasswordsRow(record.Title, record.User, record.Password.Password);
                                 break;
                            case PasswordSafePartType.End:
                                break;
                            default:
                                break;
                        }
                    }

               // }
                
                
                
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (tb_Search.Text != "")
            {
                string str_Filter = tb_Search.Text;
                bindingSource1.Filter = "title like \'%" + str_Filter + "%\' or user like \'%"+str_Filter+"%\'";
                
            }
            else bindingSource1.RemoveFilter();
        }

        private void frm_Main_Load(object sender, EventArgs e)
        {
            RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("PWSafePPCPassword", true);
            if (rk != null)
            {
                if (rk.ValueCount!=0)
                str_File_Password = rk.GetValue("Password").ToString();
            }
            else menuItem3_Click(null, null);
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            dg_Passwords.Visible = false;
            lb_Password.Visible = true;
            tb_Password.Visible = true;
            btn_OK.Visible = true;

        }



        private void btn_OK_Click(object sender, EventArgs e)
        {
            
            RegistryKey rk=  Registry.CurrentUser.OpenSubKey("Software",true).OpenSubKey("PWSafePPCPassword",true);

            if (rk == null)
            {
                RegistryKey test9999 =
            Registry.CurrentUser.OpenSubKey("Software",true).CreateSubKey("PWSafePPCPassword");
                test9999.SetValue("Password", tb_Password.Text);

            }
            else rk.SetValue("Password", tb_Password.Text);
             dg_Passwords.Visible = true;
            lb_Password.Visible = false;
            tb_Password.Visible = false;
            btn_OK.Visible = false;
           
        }

        private void frm_Main_GotFocus(object sender, EventArgs e)
        {
            tb_Search.Focus();
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("PWSafePPCPassword", true);
            if (rk != null)
            rk.DeleteValue("Password");
            str_File_Password = "";
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Authors

Svante Seleborg
Web Developer Axantum Software AB
Sweden Sweden
I've been working with all aspects of software development since 1979 - from compiler construction to management. Currently I'm an independent consultant mostly specializing in computer security. Please see my homepage for contact details.

I speak C like a native, and have a pretty good grasp of C++. The most recent five years C# has been the main development language. Traditionally Unix has been the dominating environment, but currently the scales have tipped over to Windows, due to market demands but I'm equally at home developing in both environments.

When I'm not coding I'm usually sitting on one of my 4 bikes, indoors or outdoors, on the road or in the woods.

Alphons van der Heijden
Retired Van der Heijden Holding BV
Netherlands Netherlands
I'm Alphons van der Heijden, living in Lelystad, Netherlands, Europa, Earth. And currently I'm retiring from hard working ( ;- ), owning my own company. Because I'm full of energy, and a little to young to relax ...., I don't sit down, but create and recreate software solutions, that I like. Reinventing the wheel is my second nature. My interest is in the area of Internet technologies, .NET etc. I was there in 1992 when Mosaic came out, and from that point, my life changed dramatically, and so did the world, in fact. (Y)

Dave Shaw
Software Developer
United Kingdom United Kingdom
I am currently employed as a C# / MS SQL developer for a Medical Software company working on a large enterprise system.

I have used Delphi and MSM MUMPS in previous roles and love both languages.

I'm an avid Windows Mobile fan and moderator on http://xda-developers.com. I code in C#, and C++ for WM as well as cooking custom ROMs and learning to disasm the inners of my device.

katakana2
Engineer
Romania Romania
I have some intensive experience with C#, ASP.NET and Delphi. Also I like to write API's, which I realized when I made a SmartCard library.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150427.1 | Last Updated 20 Mar 2010
Article Copyright 2009 by Svante Seleborg, Alphons van der Heijden, Dave Shaw, katakana2
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid