Logging-In with Bitcoin - Paywalls without Emails

Mark Smalley
Mark SmalleyCo-Founder and CEO at Neuroware
LOGGING-IN with BITCOIN
( a guide to life without email based registrations and paywalls )
A DEVELOPER WITHOUT CHOICE IS AN UNHAPPY DEVELOPER
WHY SHOULD WEB
DEVELOPERS CARE
ABOUT BITCOIN…?
BITCOIN SUCKS
914,000 RESULTS
https://www.google.com/search?q=bitcoin+sucks
BITCOIN ROCKS
58,800,000 RESULTS
https://www.google.com/search?q=bitcoin+rocks
64 TIMES AS GOOD AS ITS NOT
( according to Google – Nov 2013 )
WHO AM I TO TELL YOU…?
Mark Smalley – http://twitter.com/m_smalley
R1 DOT MY Sdn Bhd – http://r1.my

Been Living in Malaysia for 16 Years
Developing Web-Applications for 15 Years
MongoDB Master / NoSQL Specialist
Passion for Community Management
Family Involved with Equity Fund Management
WE ALREADY HAVE CHOICE – WE EVEN HAVE PAYPAL

• Square, Stripe, V.me, Simple, etc …
• Only available to developers in States / Europe
• Local alternatives are complicated, costly & useless
• No options for instant starts …
• No options for anonymity or the billions of us unbanked
• In Malaysia we only have PayPal and iPay88
BITCOIN THE TECHNOLOGY STACK

• Uses LevelDB to access (via JSON) a globally distributed
public ledger of all transactions
• Send and receive payments instantly and directly via
JSON-RPC calls from any server-side language …
• Existing wrappers, frameworks, documentation, libraries
and support for PHP, Ruby, NodeJS
• Still in Beta (0.8) with Market Cap of US$12.8 Billion (Nov 2013)
• Version 0.9 to bring payment requests and receipts!
THE POWER OF DISTRIBUTED LEDGERS

• Removes central point of control (and failure)
– For developers this means an ALWAYS on API

• Can be used for things other than transactions
– For developers this means timestamps and cookies

• Provides a public record and optional anonymity
– For developers this means instant sign-up without verification
LET’S BUILD SOMETHING – LOGIN WITHOUT EMAIL

Before we begin, let’s ask why do such a crazy thing…?
• We do not need to manage our own database!
• We can integrate sign-up and payment as one process
• We do not force our users to provide their identity
• Nobody needs to sign-up or apply for accounts
• We can do business globally with anyone who has internet
JUMPING INTO CODE :: TABLE OF CONTENTS
https://github.com/msmalley/BCE/tree/master/php-login

// Include BTC login class
$login = new mongobase_btc_login();

// Get user information
$user = $login->user();
// Check if user is logged-in or not...?
$logged_in = $login->logged_in($user['uid']);
// Create and display relevant HTML
$html = $login->html($logged_in, $user['address']);
echo $html;
PART ONE – GET USER INFO
$user = $login->user();

// Check if got existing UID cookie
if(isset($_COOKIE[$cookie_name]))
{
$uid = $_COOKIE[$cookie_name];
// Get existing BTC address
$addresses = $this::$btc->query(array(
'function‘ => 'getaddressesbyaccount',
'options‘ => $cookie_name.'_'.$uid
));
$address = $addresses[0];
}
PART ONE – GET USER INFO (continued)
$user = $login->user();

// Else create a new UID cookie
}else{
// Gather server settings
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$user_time = $_SERVER['REQUEST_TIME'];
// Generate unique ID
$uid = hash('sha256',$user_salt.$user_agent.$user_time);
// Set UID cookie
setcookie($cookie_name, $uid, time() + $cookie_life);
// Create new BTC address
$address = $this::$btc->query(array(
'function‘ => 'getnewaddress',
'options‘ => $cookie_name.'_'.$uid
));
}
PART TWO – CHECK IF LOGGED-IN
$logged_in = $login->logged_in($user['uid']);

// Not by default
$logged_in = false;
// Check if got balance
$uid_balance = $this::$btc->query(array(
'function’ => 'getbalance',
'options’ => $cookie_name.'_'.$uid
));
// Check if logged-in
$details = $this->timed_cookies();
$logged_in = $details['logged_in'];
if(!$logged_in && $uid_balance > 0)
{
// Not logged-in but got transactions
$logged_in = $this->set_cookies();
}
return $logged_in;
PART TWO – CHECK IF LOGGED-IN (continued)
$details = $this->timed_cookies(); // excluding sanity checks

foreach($_COOKIE as $key => $value){
$key_array = explode('_', $key);
if(count($key_array) == 2 && $key_array[0] == $cookie_name) {
$temp_uid = $key_array[1];
$txid = $_COOKIE[$cookie_name.'_'.$temp_uid];
$transactions = $this::$btc->query(array(
'function'=>'listtransactions',
'options'=>$cookie_name.'_'.$temp_uid
));
foreach($transactions as $transaction) {
$hashed_id = hash('sha256', $txid_salt.$transaction['txid']);
if($hashed_id == $txid) {
$uid = $temp_uid;
$address = $this::$btc->query(array(
'function'=>'getaddressesbyaccount',
'options'=>$cookie_name.'_'.$uid
));
$logged_in = true;
}
}
}
}
PART TWO – CHECK IF LOGGED-IN (continued)
$logged_in = $this->set_cookies(); // excluding sanity checks

$logged_in = false;
$recent_transactions = $this::$btc->query(array(
'function'=>'listtransactions',
'options'=>$cookie_name.'_'.$uid
));
$txid = $recent_transactions[0]['txid'];
$amount = $recent_transactions[0]['amount'];
if($amount > 0)
{
$logged_in = true;
$number_of_days_bought = $amount / $btc_per_day;
$new_cookie_life = 86400 * $number_of_days_bought;
// Manage Cookies
$id = hash('sha256',$txid_salt.$txid),;
setcookie($cookie_name.'_'.$uid, $id, time() + $new_cookie_life);
setcookie($this::$cookie_name, false, time() - 1);
}
return $logged_in;

Source Code: https://github.com/msmalley/BCE/tree/master/php-login
THANKS FOR LISTENING
LEARN MORE - @m_smalley

HAPPY-HACKING
1 of 18

Recommended

Neuroware.io at FINNOVASIA KL - 2016 by
Neuroware.io at FINNOVASIA KL - 2016Neuroware.io at FINNOVASIA KL - 2016
Neuroware.io at FINNOVASIA KL - 2016Mark Smalley
954 views40 slides
CBGTBT - Part 1 - Workshop introduction & primer by
CBGTBT - Part 1 - Workshop introduction & primerCBGTBT - Part 1 - Workshop introduction & primer
CBGTBT - Part 1 - Workshop introduction & primerBlockstrap.com
154.7K views72 slides
Droidcon Paris: The new Android SDK by
Droidcon Paris: The new Android SDKDroidcon Paris: The new Android SDK
Droidcon Paris: The new Android SDKPayPal
2.1K views76 slides
Integrating OAuth and Social Login Into Wordpress by
Integrating OAuth and Social Login Into WordpressIntegrating OAuth and Social Login Into Wordpress
Integrating OAuth and Social Login Into WordpressWilliam Tam
258 views33 slides
WooCommerce: payment gateways by
WooCommerce: payment gatewaysWooCommerce: payment gateways
WooCommerce: payment gatewaysRodolfo Melogli
383 views24 slides

More Related Content

Similar to Logging-In with Bitcoin - Paywalls without Emails

Skytap Google Apps by
Skytap Google AppsSkytap Google Apps
Skytap Google AppsSkytap
458 views14 slides
NZYP Project Casestudy using SilverStripe CMS by
NZYP Project Casestudy using SilverStripe CMSNZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMSCam Findlay
827 views28 slides
INSTASUITE REVIEW – DISCOUNT AND HUGE BONUS by
INSTASUITE REVIEW – DISCOUNT AND HUGE BONUSINSTASUITE REVIEW – DISCOUNT AND HUGE BONUS
INSTASUITE REVIEW – DISCOUNT AND HUGE BONUSĐức Nguyễn
335 views12 slides
CS-Cart Block.io Bitcoin Wallet by
CS-Cart Block.io Bitcoin WalletCS-Cart Block.io Bitcoin Wallet
CS-Cart Block.io Bitcoin WalletWebkul Software Pvt. Ltd.
48 views14 slides
Automating some google things by
Automating some google thingsAutomating some google things
Automating some google thingsScott Sunderland
140 views24 slides
Externalizing Authorization in Micro Services world by
Externalizing Authorization in Micro Services worldExternalizing Authorization in Micro Services world
Externalizing Authorization in Micro Services worldSitaraman Lakshminarayanan
505 views43 slides

Similar to Logging-In with Bitcoin - Paywalls without Emails(20)

Skytap Google Apps by Skytap
Skytap Google AppsSkytap Google Apps
Skytap Google Apps
Skytap458 views
NZYP Project Casestudy using SilverStripe CMS by Cam Findlay
NZYP Project Casestudy using SilverStripe CMSNZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMS
Cam Findlay827 views
INSTASUITE REVIEW – DISCOUNT AND HUGE BONUS by Đức Nguyễn
INSTASUITE REVIEW – DISCOUNT AND HUGE BONUSINSTASUITE REVIEW – DISCOUNT AND HUGE BONUS
INSTASUITE REVIEW – DISCOUNT AND HUGE BONUS
Đức Nguyễn335 views
Efficient Search Campaigns SAScon May 2012 by Steve Lock
Efficient Search Campaigns SAScon May 2012Efficient Search Campaigns SAScon May 2012
Efficient Search Campaigns SAScon May 2012
Steve Lock642 views
Cross-Platform Authentication with Google+ Sign-In by Peter Friese
Cross-Platform Authentication with Google+ Sign-InCross-Platform Authentication with Google+ Sign-In
Cross-Platform Authentication with Google+ Sign-In
Peter Friese3.8K views
The Power of Document Generation with Nintex by Brian Caauwe
The Power of Document Generation with NintexThe Power of Document Generation with Nintex
The Power of Document Generation with Nintex
Brian Caauwe792 views
API Security - OWASP top 10 for APIs + tips for pentesters by Inon Shkedy
API Security - OWASP top 10 for APIs + tips for pentestersAPI Security - OWASP top 10 for APIs + tips for pentesters
API Security - OWASP top 10 for APIs + tips for pentesters
Inon Shkedy1.1K views
Social Gold in-Flash Webinar Jan 2010 by Social Gold
Social Gold in-Flash Webinar Jan 2010Social Gold in-Flash Webinar Jan 2010
Social Gold in-Flash Webinar Jan 2010
Social Gold709 views
Social Gold In-Flash Payments Webinar by Social Gold
Social Gold In-Flash Payments WebinarSocial Gold In-Flash Payments Webinar
Social Gold In-Flash Payments Webinar
Social Gold1.3K views
SPSRED - BCS, REST ans Subscriptions by Chris Givens
SPSRED - BCS, REST ans SubscriptionsSPSRED - BCS, REST ans Subscriptions
SPSRED - BCS, REST ans Subscriptions
Chris Givens603 views
SwatiNaikResumeAug2016 by swati Naik
SwatiNaikResumeAug2016SwatiNaikResumeAug2016
SwatiNaikResumeAug2016
swati Naik32 views
How to Build a Structured Extranet Using Azure AD B2B by Andrew Oboro
How to Build a Structured Extranet Using Azure AD B2BHow to Build a Structured Extranet Using Azure AD B2B
How to Build a Structured Extranet Using Azure AD B2B
Andrew Oboro138 views

More from Mark Smalley

An Introduction to Upgradable Smart Contracts by
An Introduction to Upgradable Smart ContractsAn Introduction to Upgradable Smart Contracts
An Introduction to Upgradable Smart ContractsMark Smalley
518 views30 slides
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W... by
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...Mark Smalley
513 views35 slides
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress by
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPressBDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPressMark Smalley
472 views30 slides
BDM Meetup #1 - Blockchains for Developers - Part 01 by
BDM Meetup #1 - Blockchains for Developers - Part 01BDM Meetup #1 - Blockchains for Developers - Part 01
BDM Meetup #1 - Blockchains for Developers - Part 01Mark Smalley
798 views43 slides
Banking on The Future of Blockchains by
Banking on The Future of BlockchainsBanking on The Future of Blockchains
Banking on The Future of BlockchainsMark Smalley
2.7K views80 slides
LVLUPKL - My Life on The Blockchain by
LVLUPKL - My Life on The BlockchainLVLUPKL - My Life on The Blockchain
LVLUPKL - My Life on The BlockchainMark Smalley
1.1K views33 slides

More from Mark Smalley(18)

An Introduction to Upgradable Smart Contracts by Mark Smalley
An Introduction to Upgradable Smart ContractsAn Introduction to Upgradable Smart Contracts
An Introduction to Upgradable Smart Contracts
Mark Smalley518 views
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W... by Mark Smalley
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...
Mark Smalley513 views
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress by Mark Smalley
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPressBDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
Mark Smalley472 views
BDM Meetup #1 - Blockchains for Developers - Part 01 by Mark Smalley
BDM Meetup #1 - Blockchains for Developers - Part 01BDM Meetup #1 - Blockchains for Developers - Part 01
BDM Meetup #1 - Blockchains for Developers - Part 01
Mark Smalley798 views
Banking on The Future of Blockchains by Mark Smalley
Banking on The Future of BlockchainsBanking on The Future of Blockchains
Banking on The Future of Blockchains
Mark Smalley2.7K views
LVLUPKL - My Life on The Blockchain by Mark Smalley
LVLUPKL - My Life on The BlockchainLVLUPKL - My Life on The Blockchain
LVLUPKL - My Life on The Blockchain
Mark Smalley1.1K views
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications by Mark Smalley
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain ApplicationsBlockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications
Mark Smalley1.1K views
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014 by Mark Smalley
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014
Mark Smalley2.4K views
Programmable Money - Visual Guide to Bitcoin as a Technology by Mark Smalley
Programmable Money - Visual Guide to Bitcoin as a TechnologyProgrammable Money - Visual Guide to Bitcoin as a Technology
Programmable Money - Visual Guide to Bitcoin as a Technology
Mark Smalley11.8K views
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies by Mark Smalley
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic CurrenciesIntroducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies
Mark Smalley31.5K views
1st NoSQL Asia Event in Malaysia by Mark Smalley
1st NoSQL Asia Event in Malaysia1st NoSQL Asia Event in Malaysia
1st NoSQL Asia Event in Malaysia
Mark Smalley977 views
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia by Mark Smalley
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in MalaysiaMongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia
Mark Smalley499 views
JSON, The Argonauts and Mark by Mark Smalley
JSON, The Argonauts and MarkJSON, The Argonauts and Mark
JSON, The Argonauts and Mark
Mark Smalley1.6K views
JSON and The Argonauts by Mark Smalley
JSON and The ArgonautsJSON and The Argonauts
JSON and The Argonauts
Mark Smalley1.2K views
Serving Images with GridFS by Mark Smalley
Serving Images with GridFSServing Images with GridFS
Serving Images with GridFS
Mark Smalley4.8K views
Why I Believe MongoDB is The Dog's Bollocks by Mark Smalley
Why I Believe MongoDB is The Dog's BollocksWhy I Believe MongoDB is The Dog's Bollocks
Why I Believe MongoDB is The Dog's Bollocks
Mark Smalley2.1K views
Introducing MongoPress by Mark Smalley
Introducing MongoPressIntroducing MongoPress
Introducing MongoPress
Mark Smalley2.8K views

Recently uploaded

Combining Orchestration and Choreography for a Clean Architecture by
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean ArchitectureThomasHeinrichs1
69 views24 slides
The details of description: Techniques, tips, and tangents on alternative tex... by
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
121 views24 slides
DALI Basics Course 2023 by
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023Ivory Egg
14 views12 slides
Black and White Modern Science Presentation.pptx by
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptxmaryamkhalid2916
14 views21 slides
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...NUS-ISS
16 views28 slides
The Importance of Cybersecurity for Digital Transformation by
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital TransformationNUS-ISS
27 views26 slides

Recently uploaded(20)

Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS27 views
[2023] Putting the R! in R&D.pdf by Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
.conf Go 2023 - Data analysis as a routine by Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk93 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze by NUS-ISS
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
NUS-ISS19 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex19 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software225 views

Logging-In with Bitcoin - Paywalls without Emails

  • 1. LOGGING-IN with BITCOIN ( a guide to life without email based registrations and paywalls )
  • 2. A DEVELOPER WITHOUT CHOICE IS AN UNHAPPY DEVELOPER
  • 3. WHY SHOULD WEB DEVELOPERS CARE ABOUT BITCOIN…?
  • 6. 64 TIMES AS GOOD AS ITS NOT ( according to Google – Nov 2013 )
  • 7. WHO AM I TO TELL YOU…? Mark Smalley – http://twitter.com/m_smalley R1 DOT MY Sdn Bhd – http://r1.my Been Living in Malaysia for 16 Years Developing Web-Applications for 15 Years MongoDB Master / NoSQL Specialist Passion for Community Management Family Involved with Equity Fund Management
  • 8. WE ALREADY HAVE CHOICE – WE EVEN HAVE PAYPAL • Square, Stripe, V.me, Simple, etc … • Only available to developers in States / Europe • Local alternatives are complicated, costly & useless • No options for instant starts … • No options for anonymity or the billions of us unbanked • In Malaysia we only have PayPal and iPay88
  • 9. BITCOIN THE TECHNOLOGY STACK • Uses LevelDB to access (via JSON) a globally distributed public ledger of all transactions • Send and receive payments instantly and directly via JSON-RPC calls from any server-side language … • Existing wrappers, frameworks, documentation, libraries and support for PHP, Ruby, NodeJS • Still in Beta (0.8) with Market Cap of US$12.8 Billion (Nov 2013) • Version 0.9 to bring payment requests and receipts!
  • 10. THE POWER OF DISTRIBUTED LEDGERS • Removes central point of control (and failure) – For developers this means an ALWAYS on API • Can be used for things other than transactions – For developers this means timestamps and cookies • Provides a public record and optional anonymity – For developers this means instant sign-up without verification
  • 11. LET’S BUILD SOMETHING – LOGIN WITHOUT EMAIL Before we begin, let’s ask why do such a crazy thing…? • We do not need to manage our own database! • We can integrate sign-up and payment as one process • We do not force our users to provide their identity • Nobody needs to sign-up or apply for accounts • We can do business globally with anyone who has internet
  • 12. JUMPING INTO CODE :: TABLE OF CONTENTS https://github.com/msmalley/BCE/tree/master/php-login // Include BTC login class $login = new mongobase_btc_login(); // Get user information $user = $login->user(); // Check if user is logged-in or not...? $logged_in = $login->logged_in($user['uid']); // Create and display relevant HTML $html = $login->html($logged_in, $user['address']); echo $html;
  • 13. PART ONE – GET USER INFO $user = $login->user(); // Check if got existing UID cookie if(isset($_COOKIE[$cookie_name])) { $uid = $_COOKIE[$cookie_name]; // Get existing BTC address $addresses = $this::$btc->query(array( 'function‘ => 'getaddressesbyaccount', 'options‘ => $cookie_name.'_'.$uid )); $address = $addresses[0]; }
  • 14. PART ONE – GET USER INFO (continued) $user = $login->user(); // Else create a new UID cookie }else{ // Gather server settings $user_agent = $_SERVER['HTTP_USER_AGENT']; $user_time = $_SERVER['REQUEST_TIME']; // Generate unique ID $uid = hash('sha256',$user_salt.$user_agent.$user_time); // Set UID cookie setcookie($cookie_name, $uid, time() + $cookie_life); // Create new BTC address $address = $this::$btc->query(array( 'function‘ => 'getnewaddress', 'options‘ => $cookie_name.'_'.$uid )); }
  • 15. PART TWO – CHECK IF LOGGED-IN $logged_in = $login->logged_in($user['uid']); // Not by default $logged_in = false; // Check if got balance $uid_balance = $this::$btc->query(array( 'function’ => 'getbalance', 'options’ => $cookie_name.'_'.$uid )); // Check if logged-in $details = $this->timed_cookies(); $logged_in = $details['logged_in']; if(!$logged_in && $uid_balance > 0) { // Not logged-in but got transactions $logged_in = $this->set_cookies(); } return $logged_in;
  • 16. PART TWO – CHECK IF LOGGED-IN (continued) $details = $this->timed_cookies(); // excluding sanity checks foreach($_COOKIE as $key => $value){ $key_array = explode('_', $key); if(count($key_array) == 2 && $key_array[0] == $cookie_name) { $temp_uid = $key_array[1]; $txid = $_COOKIE[$cookie_name.'_'.$temp_uid]; $transactions = $this::$btc->query(array( 'function'=>'listtransactions', 'options'=>$cookie_name.'_'.$temp_uid )); foreach($transactions as $transaction) { $hashed_id = hash('sha256', $txid_salt.$transaction['txid']); if($hashed_id == $txid) { $uid = $temp_uid; $address = $this::$btc->query(array( 'function'=>'getaddressesbyaccount', 'options'=>$cookie_name.'_'.$uid )); $logged_in = true; } } } }
  • 17. PART TWO – CHECK IF LOGGED-IN (continued) $logged_in = $this->set_cookies(); // excluding sanity checks $logged_in = false; $recent_transactions = $this::$btc->query(array( 'function'=>'listtransactions', 'options'=>$cookie_name.'_'.$uid )); $txid = $recent_transactions[0]['txid']; $amount = $recent_transactions[0]['amount']; if($amount > 0) { $logged_in = true; $number_of_days_bought = $amount / $btc_per_day; $new_cookie_life = 86400 * $number_of_days_bought; // Manage Cookies $id = hash('sha256',$txid_salt.$txid),; setcookie($cookie_name.'_'.$uid, $id, time() + $new_cookie_life); setcookie($this::$cookie_name, false, time() - 1); } return $logged_in; Source Code: https://github.com/msmalley/BCE/tree/master/php-login
  • 18. THANKS FOR LISTENING LEARN MORE - @m_smalley HAPPY-HACKING