25 Kasım 2013 Pazartesi
Program Şifremizi Kodlayarak saklamak
Giriş Formu:
Imports Microsoft.Win32 'register için Public Class GirisFrm Dim zx As String Private Sub GirisFrm_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed End End Sub Private Sub GirisFrm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Try Dim regkey As RegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", False) Dim subregkey As RegistryKey = regkey.OpenSubKey("unknown", False) sifre = subregkey.GetValue("watchword", Environment.UserDomainName.ToString) If sifre = Environment.UserDomainName.ToString Then Call YeniRegisterKayitAc() subregkey.Close() regkey.Close() UyariLbl.Text = "" ParolaFrm.SifreliKoduCoz() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text) End Try End Sub Public Sub YeniRegisterKayitAc() For Each t In Environment.UserDomainName.ToString say += 1 If say = 1 Then secenek &= Convert.ToInt32(t) & ":abcçdefgğhıijklmnoöpqrsştuüvwxyz" ElseIf say = 2 Then secenek &= Convert.ToInt32(t) & ":zyxwvüutşsrqpöonmlkjiıhğgfedçcba" ElseIf say = 3 Then secenek &= Convert.ToInt32(t) & ":öonmlkjiıhğgfedçcbazyxwvüutşsrqp" say = 0 End If Next ParolaFrm.YeniSifreTxt1.Text = secenek ParolaFrm.YeniSifreyKaydet() End Sub Private Sub GirisBtn_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles GirisBtn.MouseDown If e.Button = Windows.Forms.MouseButtons.Middle Then SifreTxt.Text = Sifre End If End Sub Private Sub GirisBtn_Click(sender As System.Object, e As System.EventArgs) Handles GirisBtn.Click Timer1.Stop() Select Case SifreTxt.Text Case Is = "" Timer1.Interval = 2000 Timer1.Start() Beep() UyariLbl.Text = "Şifreyi Giriniz" SifreTxt.Focus() Case Is = sifre GirisBtn.Enabled = True MainFrm.Show() Me.Hide() Case Else Timer1.Start() sayac += 1 Timer1.Interval = 2000 Timer1.Start() If sayac = 3 Then UyariLbl.Text = "Yetkili değilsiniz." : GirisBtn.Enabled = False If sayac < 3 Then UyariLbl.Text = "Şifreyi Yanlış Girdiniz" SifreTxt.Text = "" SifreTxt.Focus() End Select End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick UyariLbl.Text = Nothing Timer1.Stop() End Sub Private Sub SifreTxt_MouseLeave(sender As System.Object, e As System.EventArgs) Handles SifreTxt.MouseLeave If Environment.UserDomainName.ToString = sifre Then Dim tooltip As New ToolTip() tooltip.SetToolTip(SifreTxt, "Programın ilk kurulumdaki şifresi" _ & vbCrLf & "(" & Environment.UserDomainName.ToString & ")" _ & vbCrLf & " Bilgisayarınızın Adıdır" _ & vbCrLf & "Harfler Büyükse Aynen girin" _ & vbCrLf & "Sonra Şifrenizi değiştirin") End If End Sub End Class
MainForm :
Public Class MainFrm Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click ParolaFrm.ShowDialog() End Sub End Class
Şifre Değiştirme ve kodlama Formu :
Imports Microsoft.Win32 'register için Public Class ParolaFrm Dim zx As String Private Sub Form2_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed GirisFrm.SifreTxt.Text = Nothing GirisFrm.Show() Me.Hide() End Sub Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Call SifreliKoduCoz() GirisFrm.SifreTxt.PasswordChar = Nothing GirisFrm.SifreTxt.PasswordChar = "*" Label4.Text = "" EskiSifreTxt.Text = Nothing Me.EskiSifreTxt.Focus() End Sub Public Sub SifreliKoduCoz() Try Dim regkey As RegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", False) Dim subregkey As RegistryKey = regkey.OpenSubKey("unknown", False) sifre = subregkey.GetValue("watchword", Environment.UserDomainName.ToString) subregkey.Close() regkey.Close() ButunTxt &= sifre Dim s As String = "abcçdefgğhıijklmnoöpqrsştuüvwxyz" For Each st In s ButunTxt = ButunTxt.Replace(st, "") Next ButunTxt = ButunTxt.Replace(":", vbNewLine) IO.File.WriteAllText("tx.txt", ButunTxt) For Each Me.zx In IO.File.ReadAllLines("tx.txt") y = Convert.ToInt32(zx) u &= Convert.ToChar(y) Next sifre = u ButunTxt = String.Empty u = String.Empty IO.File.Delete("tx.txt") Catch ex As Exception Return 'MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text) End Try End Sub Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged If CheckBox1.Checked = True Then EskiSifreTxt.UseSystemPasswordChar = False EskiSifreTxt.PasswordChar = "" YeniSifreTxt1.UseSystemPasswordChar = False YeniSifreTxt1.PasswordChar = "" YeniSifreTxt2.UseSystemPasswordChar = False YeniSifreTxt2.PasswordChar = "" If EskiSifreTxt.Text = sifre Then ParolaKaydetBtn.Enabled = True Else ParolaKaydetBtn.Enabled = False End If Else EskiSifreTxt.UseSystemPasswordChar = True EskiSifreTxt.PasswordChar = "*" YeniSifreTxt1.UseSystemPasswordChar = True YeniSifreTxt1.PasswordChar = "*" YeniSifreTxt2.UseSystemPasswordChar = True YeniSifreTxt2.PasswordChar = "*" YeniSifreTxt1.Text = Nothing YeniSifreTxt2.Text = Nothing ParolaKaydetBtn.Enabled = False End If End Sub Private Sub ParolaKaydetBtn_Click(sender As System.Object, e As System.EventArgs) Handles ParolaKaydetBtn.Click If Not YeniSifreTxt1.Text = YeniSifreTxt2.Text Then MessageBox.Show("Şifre ve Tekrarı uyuşmadı") Label2.Visible = False YeniSifreTxt1.Text = Nothing YeniSifreTxt2.Text = Nothing ParolaKaydetBtn.Enabled = False Else Label2.Visible = True YeniSifreTxt1.Visible = True YeniSifreTxt2.Visible = True ParolaKaydetBtn.Enabled = True TextSonu.Text = YeniSifreTxt1.Text Application.DoEvents() For Each t In TextSonu.Text say += 1 If say = 1 Then secenek &= Convert.ToInt32(t) & ":abcçdefgğhıijklmnoöpqrsştuüvwxyz" ElseIf say = 2 Then secenek &= Convert.ToInt32(t) & ":zyxwvüutşsrqpöonmlkjiıhğgfedçcba" ElseIf say = 3 Then secenek &= Convert.ToInt32(t) & ":öonmlkjiıhğgfedçcbazyxwvüutşsrqp" say = 0 End If Next YeniSifreTxt1.Text = secenek Timer1.Interval = 2000 Timer1.Start() Label4.Text = "Kodlandı" YeniSifreyKaydet() End If End Sub Public Sub YeniSifreyKaydet() Dim regkey As RegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", True) regkey.CreateSubKey("unknown") Dim subregkey As RegistryKey = regkey.OpenSubKey("unknown", True) subregkey.SetValue("watchword", YeniSifreTxt1.Text) subregkey.Close() regkey.Close() End Sub Public Sub DomainKodla() Application.DoEvents() For Each t In TextSonu.Text say += 1 If say = 1 Then secenek &= Convert.ToInt32(t) & ":abcçdefgğhıijklmnoöpqrsştuüvwxyz" ElseIf say = 2 Then secenek &= Convert.ToInt32(t) & ":zyxwvüutşsrqpöonmlkjiıhğgfedçcba" ElseIf say = 3 Then secenek &= Convert.ToInt32(t) & ":öonmlkjiıhğgfedçcbazyxwvüutşsrqp" say = 0 End If Next YeniSifreTxt1.Text = secenek End Sub Private Sub EskiSifreTxt_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles EskiSifreTxt.KeyDown 'Kısa yoldab ve gizlice eski parolayı hatırlatma (watchword=parola)-(unknown=bilinmeyen) If (e.Alt AndAlso e.KeyCode = Keys.S) Then Dim regkey As RegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", False) Dim subregkey As RegistryKey = regkey.OpenSubKey("unknown", False) sifre = subregkey.GetValue("watchword", Environment.UserDomainName.ToString) Call SifreliKoduCoz() Me.Text = sifre Timer1.Interval = 2000 Timer1.Start() subregkey.Close() regkey.Close() End If End Sub Private Sub EskiSifreTxt_TextChanged(sender As System.Object, e As System.EventArgs) Handles EskiSifreTxt.TextChanged If Me.EskiSifreTxt.Text = sifre Then ParolaKaydetBtn.Enabled = True End If End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick Me.Text = "Şifre Değiştir" Label4.Text = "" Timer1.Stop() End Sub End Class
Modul :
Module Module1 Public ButunTxt, secenek, u As String Public DsyAdi As String Public TextSonu As New TextBox Public y As Int32 Public say As Int32 Public sifre As String Public sayac As Integer = 0 Public TxtOku As IO.StreamReader Public Yaz As IO.StreamWriter End Module
Hiç yorum yok:
Yorum Gönder
Sonraki Kayıt
Önceki Kayıt
Ana Sayfa
Kaydol:
Kayıt Yorumları (Atom)
Hiç yorum yok:
Yorum Gönder